From: Robert Griesemer Date: Tue, 7 Jun 2022 17:43:51 +0000 (-0700) Subject: go/types, types2: better error message if type is not in type set X-Git-Tag: go1.19beta1~26 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=269bf7e855;p=gostls13.git go/types, types2: better error message if type is not in type set Fixes #40350. Change-Id: Ia654d6b854971700ca618692a864265557122b23 Reviewed-on: https://go-review.googlesource.com/c/go/+/410876 Reviewed-by: Robert Findley Reviewed-by: Robert Griesemer --- diff --git a/src/cmd/compile/internal/types2/instantiate.go b/src/cmd/compile/internal/types2/instantiate.go index f338e28d2e..45f7e43ccf 100644 --- a/src/cmd/compile/internal/types2/instantiate.go +++ b/src/cmd/compile/internal/types2/instantiate.go @@ -277,7 +277,7 @@ func (check *Checker) implements(V, T Type) error { if alt != nil { return errorf("%s does not implement %s (possibly missing ~ for %s in constraint %s)", V, T, alt, T) } else { - return errorf("%s does not implement %s", V, T) + return errorf("%s does not implement %s (%s missing in %s)", V, T, V, Ti.typeSet().terms) } } diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go new file mode 100644 index 0000000000..7ffd551c2e --- /dev/null +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go @@ -0,0 +1,16 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type number interface { + ~float64 | ~int | ~int32 + float64 | ~int32 +} + +func f[T number]() {} + +func _() { + _ = f[int /* ERROR int does not implement number \(int missing in float64 | ~int32\)*/] +} diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 6091b0b381..e6b731f241 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -277,7 +277,7 @@ func (check *Checker) implements(V, T Type) error { if alt != nil { return errorf("%s does not implement %s (possibly missing ~ for %s in constraint %s)", V, T, alt, T) } else { - return errorf("%s does not implement %s", V, T) + return errorf("%s does not implement %s (%s missing in %s)", V, T, V, Ti.typeSet().terms) } } diff --git a/src/go/types/testdata/fixedbugs/issue40350.go b/src/go/types/testdata/fixedbugs/issue40350.go new file mode 100644 index 0000000000..7ffd551c2e --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue40350.go @@ -0,0 +1,16 @@ +// Copyright 2022 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package p + +type number interface { + ~float64 | ~int | ~int32 + float64 | ~int32 +} + +func f[T number]() {} + +func _() { + _ = f[int /* ERROR int does not implement number \(int missing in float64 | ~int32\)*/] +}