1
0
mirror of https://github.com/golang/go synced 2024-11-16 21:04:45 -07:00

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 <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-06-07 10:43:51 -07:00
parent d4fb93be87
commit 269bf7e855
4 changed files with 34 additions and 2 deletions

View File

@ -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)
}
}

View File

@ -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\)*/]
}

View File

@ -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)
}
}

View File

@ -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\)*/]
}