github.com/golangci/go-tools@v0.0.0-20190318060251-af6baa5dc196/unused/testdata/src/fields/fields.go (about)

     1  // Test of field usage detection
     2  
     3  package pkg
     4  
     5  type t1 struct{ f11, f12 int }
     6  type t2 struct{ f21, f22 int }
     7  type t3 struct{ f31 t4 }
     8  type t4 struct{ f41 int }
     9  type t5 struct{ f51 int }
    10  type t6 struct{ f61 int }
    11  type t7 struct{ f71 int }
    12  type m1 map[string]t7
    13  type t8 struct{ f81 int }
    14  type t9 struct{ f91 int }
    15  type t10 struct{ f101 int }
    16  type t11 struct{ f111 int }
    17  type s1 []t11
    18  type t12 struct{ f121 int }
    19  type s2 []t12
    20  type t13 struct{ f131 int }
    21  type t14 struct{ f141 int }
    22  type a1 [1]t14
    23  type t15 struct{ f151 int }
    24  type a2 [1]t15
    25  type t16 struct{ f161 int }
    26  type t17 struct{ f171, f172 int } // MATCH /t17 is unused/
    27  // MATCH:28 /f183 is unused/
    28  type t18 struct{ f181, f182, f183 int } // MATCH /f182 is unused/
    29  
    30  type t19 struct{ f191 int }
    31  type m2 map[string]t19
    32  
    33  type t20 struct{ f201 int }
    34  type m3 map[string]t20
    35  
    36  type t21 struct{ f211, f212 int } // MATCH /f211 is unused/
    37  
    38  func foo() {
    39  	_ = t10{1}
    40  	_ = t21{f212: 1}
    41  	_ = []t1{{1, 2}}
    42  	_ = t2{1, 2}
    43  	_ = []struct{ a int }{{1}}
    44  
    45  	// XXX
    46  	// _ = []struct{ foo struct{ bar int } }{{struct{ bar int }{1}}}
    47  
    48  	_ = []t1{t1{1, 2}}
    49  	_ = []t3{{t4{1}}}
    50  	_ = map[string]t5{"a": {1}}
    51  	_ = map[t6]string{{1}: "a"}
    52  	_ = m1{"a": {1}}
    53  	_ = map[t8]t8{{}: {1}}
    54  	_ = map[t9]t9{{1}: {}}
    55  	_ = s1{{1}}
    56  	_ = s2{2: {1}}
    57  	_ = [...]t13{{1}}
    58  	_ = a1{{1}}
    59  	_ = a2{0: {1}}
    60  	_ = map[[1]t16]int{{{1}}: 1}
    61  	y := struct{ x int }{} // MATCH /x is unused/
    62  	_ = y
    63  	_ = t18{f181: 1}
    64  	_ = []m2{{"a": {1}}}
    65  	_ = [][]m3{{{"a": {1}}}}
    66  }
    67  
    68  func init() { foo() }