aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2022-06-07 10:43:51 -0700
committerRobert Griesemer <gri@golang.org>2022-06-07 21:37:18 +0000
commit269bf7e855da04e664fe8d7ffb654c4d0b1439f5 (patch)
tree0dab47838663d0be71f4bf9f0bf0fb358e25e3c9
parentd4fb93be87c38aaf0f68ad91852f9f83be726262 (diff)
downloadgo-269bf7e855da04e664fe8d7ffb654c4d0b1439f5.tar.gz
go-269bf7e855da04e664fe8d7ffb654c4d0b1439f5.zip
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>
-rw-r--r--src/cmd/compile/internal/types2/instantiate.go2
-rw-r--r--src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go16
-rw-r--r--src/go/types/instantiate.go2
-rw-r--r--src/go/types/testdata/fixedbugs/issue40350.go16
4 files changed, 34 insertions, 2 deletions
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\)*/]
+}