3 type T1 struct{ x int }
10 type T3 struct{ y *T1 }
13 // Test struct field writes.
15 s1.x = 10 // want "unused write to field x"
19 s2[1] = 10 // want "unused write to array index 1:int"
21 // Test range variables of struct type.
22 s3 := []T1{T1{x: 100}}
23 for i, v := range s3 {
24 v.x = i // want "unused write to field x"
27 // Test the case where a different field is read after the write.
28 s4 := []T2{T2{x: 1, y: 2}}
29 for i, v := range s4 {
30 v.x = i // want "unused write to field x"
35 func (t T1) BadValueReceiverWrite(v T2) {
36 t.x = 10 // want "unused write to field x"
37 v.y = 20 // want "unused write to field y"
40 func GoodWrites(m map[int]int) {
41 // A map is copied by reference such that a write will affect the original map.
44 // Test struct field writes.
52 // Current the checker doesn't distinguish index 1 and index 2.
55 // Test range variables of struct type.
56 s3 := []T1{T1{x: 100}}
57 for i, v := range s3 { // v is a copy
59 _ = v.x // still a usage
62 // Test an object with multiple fields.
63 o := &T2{x: 10, y: 20}
66 // Test an object of embedded struct/pointer type.
72 func (t *T1) GoodPointerReceiverWrite(v *T2) {