1 // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: bug285
3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test for issue 778: Map key values that are assignment
8 // compatible with the map key type must be accepted according
9 // to the spec: http://golang.org/doc/go_spec.html#Indexes .
17 func (t *T2) f() int { return t.x }
23 mb[false] = 42 // this should work: false is assignment compatible with B
53 mf[func(x int) {}] = 42
73 var i0 interface{} = z
75 m0 := make(map[interface{}]int)
76 m1 := make(map[I1]int)
77 m2 := make(map[I2]int)
80 m0[z] = 42 // this should work: z is assignment-compatible with interface{}
83 })] = 42 // this should work: *struct{x int} is assignment-compatible with interface{}
84 m0[p] = 42 // this should work: p is assignment-compatible with interface{}
85 m0[false] = 42 // this should work: false is assignment-compatible with interface{}
86 m0[17] = 42 // this should work: 17 is assignment-compatible with interface{}
87 m0["foo"] = 42 // this should work: "foo" is assignment-compatible with interface{}
93 })] = 42 // this should work: *struct{x int} is assignment-compatible with I1
94 m1[false] = 42 // this should work: false is assignment-compatible with I1
95 m1[17] = 42 // this should work: 17 is assignment-compatible with I1
96 m1["foo"] = 42 // this should work: "foo" is assignment-compatible with I1
98 m2[new(T2)] = 42 // this should work: *T2 is assignment-compatible with I2
103 bug286.go:23: invalid map index false - need type B
104 bug286.go:80: invalid map index z - need type interface { }
105 bug286.go:83: invalid map index new(struct { x int }) - need type interface { }
106 bug286.go:84: invalid map index p - need type interface { }
107 bug286.go:85: invalid map index false - need type interface { }
108 bug286.go:86: invalid map index 17 - need type interface { }
109 bug286.go:87: invalid map index "foo" - need type interface { }
110 bug286.go:93: invalid map index new(struct { x int }) - need type I1
111 bug286.go:94: invalid map index false - need type I1
112 bug286.go:95: invalid map index 17 - need type I1
113 bug286.go:96: invalid map index "foo" - need type I1
114 bug286.go:99: invalid map index new(T2) - need type I2
115 bug286.go:100: invalid map index t2 - need type I2