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:
parent
d4fb93be87
commit
269bf7e855
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
16
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go
vendored
Normal file
16
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go
vendored
Normal 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\)*/]
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
16
src/go/types/testdata/fixedbugs/issue40350.go
vendored
Normal file
16
src/go/types/testdata/fixedbugs/issue40350.go
vendored
Normal 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\)*/]
|
||||
}
|
Loading…
Reference in New Issue
Block a user