diff options
author | Robert Griesemer <gri@golang.org> | 2022-01-26 22:48:44 -0800 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2022-01-31 20:35:07 +0000 |
commit | 360e1b8197b78685cf08ab5914aa629fb739b2c3 (patch) | |
tree | 685df3a0f7eadbfb6891550e0c9071e7fc682bba /src/cmd/compile/internal/types2/predicates.go | |
parent | 41f485b9a7d8fd647c415be1d11b612063dff21c (diff) | |
download | go-360e1b8197b78685cf08ab5914aa629fb739b2c3.tar.gz go-360e1b8197b78685cf08ab5914aa629fb739b2c3.zip |
go/types, types2: fix implements and identical predicates
- Use the correct predicate in Checker.implements: for interfaces
we cannot use the API Comparable because it always returns true
for all non-type parameter interface types: Comparable simply
answers if == and != is permitted, and it's always been permitted
for interfaces. Instead we must use Interface.IsComparable which
looks at the type set of an interface.
- When comparing interfaces for identity, we must also consider the
whether the type sets have the comparable bit set.
With this change, `any` doesn't implement `comparable` anymore. This
only matters for generic functions and types, and the API functions.
It does mean that for now (until we allow type-constrained interfaces
for general non-constraint use, at some point in the future) a type
parameter that needs to be comparable cannot be instantiated with an
interface anymore.
For #50646.
Change-Id: I7e7f711bdcf94461f330c90509211ec0c2cf3633
Reviewed-on: https://go-review.googlesource.com/c/go/+/381254
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/predicates.go')
-rw-r--r-- | src/cmd/compile/internal/types2/predicates.go | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/types2/predicates.go b/src/cmd/compile/internal/types2/predicates.go index cc3c76e695..003e58db38 100644 --- a/src/cmd/compile/internal/types2/predicates.go +++ b/src/cmd/compile/internal/types2/predicates.go @@ -306,6 +306,9 @@ func identical(x, y Type, cmpTags bool, p *ifacePair) bool { if y, ok := y.(*Interface); ok { xset := x.typeSet() yset := y.typeSet() + if xset.comparable != yset.comparable { + return false + } if !xset.terms.equal(yset.terms) { return false } |