Skip to content

Commit 642fd5f

Browse files
griesemergopherbot
authored andcommitted
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 <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gopher Robot <[email protected]>
1 parent 9123221 commit 642fd5f

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

src/cmd/compile/internal/types2/typeset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool
352352
i := 0
353353
for _, t := range terms {
354354
assert(t.typ != nil)
355-
if Comparable(t.typ) {
355+
if comparable(t.typ, false /* strictly comparable */, nil, nil) {
356356
terms[i] = t
357357
i++
358358
}

src/go/types/typeset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ func intersectTermLists(xterms termlist, xcomp bool, yterms termlist, ycomp bool
350350
i := 0
351351
for _, t := range terms {
352352
assert(t.typ != nil)
353-
if Comparable(t.typ) {
353+
if comparable(t.typ, false /* strictly comparable */, nil, nil) {
354354
terms[i] = t
355355
i++
356356
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
type C1 interface {
8+
comparable
9+
}
10+
11+
type C2 interface {
12+
comparable
13+
[2]any | int
14+
}
15+
16+
func G1[T C1](t T) { _ = t == t }
17+
func G2[T C2](t T) { _ = t == t }
18+
19+
func F1[V [2]any](v V) {
20+
_ = G1[V /* ERROR "V does not implement comparable" */]
21+
_ = G1[[2]any]
22+
_ = G1[int]
23+
}
24+
25+
func F2[V [2]any](v V) {
26+
_ = G2[V /* ERROR "V does not implement C2" */]
27+
_ = G2[[ /* ERROR "\[2\]any does not implement C2 \(\[2\]any missing in int\)" */ 2]any]
28+
_ = G2[int]
29+
}

0 commit comments

Comments
 (0)