mirror of
https://github.com/golang/go
synced 2024-11-18 16:44:43 -07:00
go.tools/go/types: map keys must be comparable
R=adonovan CC=golang-dev https://golang.org/cl/12102044
This commit is contained in:
parent
33d57bf48f
commit
4ae33302a4
@ -60,9 +60,6 @@ func TestStdtest(t *testing.T) {
|
||||
case "goto.go", "label1.go":
|
||||
// TODO(gri) implement missing label checks
|
||||
continue
|
||||
case "map1.go":
|
||||
// TODO(gri) fix map key checking
|
||||
continue
|
||||
case "sizeof.go", "switch.go":
|
||||
// TODO(gri) tone down duplicate checking in expression switches
|
||||
continue
|
||||
|
4
go/types/testdata/cycles.src
vendored
4
go/types/testdata/cycles.src
vendored
@ -63,7 +63,7 @@ type (
|
||||
I6 interface{ I5 }
|
||||
|
||||
// maps
|
||||
M0 map[M0]M0
|
||||
M0 map[M0 /* ERROR "invalid map key" */ ]M0
|
||||
|
||||
// channels
|
||||
C0 chan C0
|
||||
@ -103,7 +103,7 @@ func _() {
|
||||
i0 /* ERROR "cycle" */ interface{ i0 }
|
||||
|
||||
// maps
|
||||
m0 map[m0]m0
|
||||
m0 map[m0 /* ERROR "invalid map key" */ ]m0
|
||||
|
||||
// channels
|
||||
c0 chan c0
|
||||
|
@ -293,6 +293,15 @@ func (check *checker) typ0(e ast.Expr, def *Named, cycleOk bool) Type {
|
||||
|
||||
typ.key = check.typ(e.Key, nil, true)
|
||||
typ.elt = check.typ(e.Value, nil, true)
|
||||
|
||||
// spec: "The comparison operators == and != must be fully defined
|
||||
// for operands of the key type; thus the key type must not be a
|
||||
// function, map, or slice."
|
||||
if !isComparable(typ.key) {
|
||||
check.errorf(e.Key.Pos(), "invalid map key type %s", typ.key)
|
||||
// ok to continue
|
||||
}
|
||||
|
||||
return typ
|
||||
|
||||
case *ast.ChanType:
|
||||
|
Loading…
Reference in New Issue
Block a user