diff options
author | Robert Griesemer <gri@golang.org> | 2022-12-28 14:21:50 -0800 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-12-29 17:47:20 +0000 |
commit | 642fd5f7cea0f1e214bacfd3a530ee12f9721899 (patch) | |
tree | f03ce95686f8e7a8442b61f8d8c8e5956613f2ad | |
parent | 9123221ccf3c80c741ead5b6f2e960573b1676b9 (diff) | |
download | go-642fd5f7cea0f1e214bacfd3a530ee12f9721899.tar.gz go-642fd5f7cea0f1e214bacfd3a530ee12f9721899.zip |
go/types, types2: use strict comparability for type set intersection
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>
-rw-r--r-- | src/cmd/compile/internal/types2/typeset.go | 2 | ||||
-rw-r--r-- | src/go/types/typeset.go | 2 | ||||
-rw-r--r-- | src/internal/types/testdata/fixedbugs/issue57486.go | 29 |
3 files changed, 31 insertions, 2 deletions
diff --git a/src/cmd/compile/internal/types2/typeset.go b/src/cmd/compile/internal/types2/typeset.go index 391ea8cd79..673cadca90 100644 --- a/src/cmd/compile/internal/types2/typeset.go +++ b/src/cmd/compile/internal/types2/typeset.go @@ -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++ } diff --git a/src/go/types/typeset.go b/src/go/types/typeset.go index 35a32972e0..d68446df66 100644 --- a/src/go/types/typeset.go +++ b/src/go/types/typeset.go @@ -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 index 0000000000..ff9e3d1db5 --- /dev/null +++ b/src/internal/types/testdata/fixedbugs/issue57486.go @@ -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] +} |