diff --git a/src/cmd/compile/internal/types2/testdata/typeparams.go2 b/src/cmd/compile/internal/types2/testdata/typeparams.go2 index 4c053bbf1e..2fa67985f7 100644 --- a/src/cmd/compile/internal/types2/testdata/typeparams.go2 +++ b/src/cmd/compile/internal/types2/testdata/typeparams.go2 @@ -66,7 +66,7 @@ func new(type T)() *T { var _ = new /* ERROR cannot use generic function new */ var _ *int = new(int)() -func _(type T)(map[T /* ERROR invalid map key type */]int) // w/o contract we don't know if T is comparable +func _(type T)(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(type T1)(struct{T1}) int var _ = f1(int)(struct{T1}{}) diff --git a/src/cmd/compile/internal/types2/typexpr.go b/src/cmd/compile/internal/types2/typexpr.go index 2393bd6ec8..a7240e8a2b 100644 --- a/src/cmd/compile/internal/types2/typexpr.go +++ b/src/cmd/compile/internal/types2/typexpr.go @@ -550,7 +550,11 @@ func (check *Checker) typInternal(e0 syntax.Expr, def *Named) (T Type) { // it is safe to continue in any case (was issue 6667). check.atEnd(func() { if !Comparable(typ.key) { - check.errorf(e.Key.Pos(), "invalid map key type %s", typ.key) + var why string + if typ.key.TypeParam() != nil { + why = " (missing comparable constraint)" + } + check.errorf(e.Key.Pos(), "invalid map key type %s%s", typ.key, why) } })