]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: use strict comparability for type set intersection
authorRobert Griesemer <gri@golang.org>
Wed, 28 Dec 2022 22:21:50 +0000 (14:21 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 29 Dec 2022 17:47:20 +0000 (17:47 +0000)
Fixes #57486.

Change-Id: I4b71199a724718886ce6d7a49e96a9ebdcbcf737
Reviewed-on: https://go-review.googlesource.com/c/go/+/459816
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/compile/internal/types2/typeset.go
src/go/types/typeset.go
src/internal/types/testdata/fixedbugs/issue57486.go [new file with mode: 0644]

index 391ea8cd79541db7f0eb8b11f93c5926142d37ba..673cadca902058625a517b87e11617ea39f805c3 100644 (file)
@@ -352,7 +352,7 @@ func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool
                i := 0
                for _, t := range terms {
                        assert(t.typ != nil)
-                       if Comparable(t.typ) {
+                       if comparable(t.typ, false /* strictly comparable */, nil, nil) {
                                terms[i] = t
                                i++
                        }
index 35a32972e0bacbe21ccab51da44397d989dd7fac..d68446df66d7f49f44d97e7e9b0099dcdf715fe3 100644 (file)
@@ -350,7 +350,7 @@ func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool
                i := 0
                for _, t := range terms {
                        assert(t.typ != nil)
-                       if Comparable(t.typ) {
+                       if comparable(t.typ, false /* strictly comparable */, nil, nil) {
                                terms[i] = t
                                i++
                        }
diff --git a/src/internal/types/testdata/fixedbugs/issue57486.go b/src/internal/types/testdata/fixedbugs/issue57486.go
new file mode 100644 (file)
index 0000000..ff9e3d1
--- /dev/null
@@ -0,0 +1,29 @@
+// 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 C1 interface {
+       comparable
+}
+
+type C2 interface {
+       comparable
+       [2]any | int
+}
+
+func G1[T C1](t T) { _ = t == t }
+func G2[T C2](t T) { _ = t == t }
+
+func F1[V [2]any](v V) {
+       _ = G1[V /* ERROR "V does not implement comparable" */]
+       _ = G1[[2]any]
+       _ = G1[int]
+}
+
+func F2[V [2]any](v V) {
+       _ = G2[V /* ERROR "V does not implement C2" */]
+       _ = G2[[ /* ERROR "\[2\]any does not implement C2 \(\[2\]any missing in int\)" */ 2]any]
+       _ = G2[int]
+}