]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: better error message if type is not in type set
authorRobert Griesemer <gri@golang.org>
Tue, 7 Jun 2022 17:43:51 +0000 (10:43 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 7 Jun 2022 21:37:18 +0000 (21:37 +0000)
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>
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue40350.go [new file with mode: 0644]
src/go/types/instantiate.go
src/go/types/testdata/fixedbugs/issue40350.go [new file with mode: 0644]

index f338e28d2e5875af10e0734179622134b1ac35a8..45f7e43ccf30907cce4bac1daa69523d6177e4c7 100644 (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)
                }
        }
 
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 (file)
index 0000000..7ffd551
--- /dev/null
@@ -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\)*/]
+}
index 6091b0b38147a779ce4177063c1b9239da09763a..e6b731f241d25d41bfa219a5eb2678607f06e880 100644 (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)
                }
        }
 
diff --git a/src/go/types/testdata/fixedbugs/issue40350.go b/src/go/types/testdata/fixedbugs/issue40350.go
new file mode 100644 (file)
index 0000000..7ffd551
--- /dev/null
@@ -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\)*/]
+}