mirror of https://github.com/golang/go.git
go/types: match types2 error for invalid map key
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>
This commit is contained in:
parent
9a1d3b0ad2
commit
6bedf4a2b4
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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}{})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue