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>
This commit is contained in:
Robert Griesemer 2022-12-28 14:21:50 -08:00 committed by Gopher Robot
parent 9123221ccf
commit 642fd5f7ce
3 changed files with 31 additions and 2 deletions

View 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++
}

View 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++
}

View file

@ -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]
}