]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: match types2 error for invalid map key
authorRobert Griesemer <gri@golang.org>
Thu, 18 Aug 2022 23:59:10 +0000 (16:59 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 19 Aug 2022 19:39:50 +0000 (19:39 +0000)
Use "invalid" rather than "incomparable" in error message for map key
types that are not comparable. This is the original compiler error
message and many tests check for this specific message. The type
checker does provide an additional explanation if the reason for
the error is not obvious (e.g. for type parameters).

For #54511.

Change-Id: Idb76c48b4dfbfd66a7deac728a552e07f14e06d7
Reviewed-on: https://go-review.googlesource.com/c/go/+/424905
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
src/go/types/testdata/check/cycles0.go
src/go/types/testdata/check/typeparams.go
src/go/types/typexpr.go

index 27b6111822948bc0556afdd8096903f8eb0c92bc..998f9f7da980116ccbae32f6fb796766fe4c19fa 100644 (file)
@@ -66,7 +66,7 @@ type (
        I6 interface{ I5 }
 
        // maps
-       M0 map[M0 /* ERROR incomparable map key */ ]M0
+       M0 map[M0 /* ERROR invalid map key */ ]M0
 
        // channels
        C0 chan C0
@@ -115,7 +115,7 @@ func _() {
                i0 /* ERROR cycle */ interface{ i0 }
 
                // maps
-               m0 map[m0 /* ERROR incomparable map key */ ]m0
+               m0 map[m0 /* ERROR invalid map key */ ]m0
 
                // channels
                c0 chan c0
@@ -124,10 +124,10 @@ func _() {
 
 // test cases for issue 6667
 
-type A [10]map[A /* ERROR incomparable map key */ ]bool
+type A [10]map[A /* ERROR invalid map key */ ]bool
 
 type S struct {
-       m map[S /* ERROR incomparable map key */ ]bool
+       m map[S /* ERROR invalid map key */ ]bool
 }
 
 // test cases for issue 7236
index 199828f55fb18d6579b7f18fe22ed4569206a476..95bd3e46b919a91227b689f15de6c5229fdec541 100644 (file)
@@ -75,7 +75,7 @@ func new[T any]() *T {
 var _ = new /* ERROR cannot use generic function new */
 var _ *int = new[int]()
 
-func _[T any](map[T /* ERROR incomparable map key type T \(missing comparable constraint\) */]int) {} // w/o constraint we don't know if T is comparable
+func _[T any](map[T /* ERROR invalid map key type T \(missing comparable constraint\) */]int) {} // w/o constraint we don't know if T is comparable
 
 func f1[T1 any](struct{T1 /* ERROR cannot be a .* type parameter */ }) int { panic(0) }
 var _ = f1[int](struct{T1}{})
index b02929df224725d9b5555ed496460c956de02614..397bd75db336f3448188e3697f29b1037f632311 100644 (file)
@@ -348,7 +348,7 @@ func (check *Checker) typInternal(e0 ast.Expr, def *Named) (T Type) {
                                if isTypeParam(typ.key) {
                                        why = " (missing comparable constraint)"
                                }
-                               check.errorf(e.Key, _IncomparableMapKey, "incomparable map key type %s%s", typ.key, why)
+                               check.errorf(e.Key, _IncomparableMapKey, "invalid map key type %s%s", typ.key, why)
                        }
                }).describef(e.Key, "check map key %s", typ.key)