]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: fix implements and identical predicates
authorRobert Griesemer <gri@golang.org>
Thu, 27 Jan 2022 06:48:44 +0000 (22:48 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 31 Jan 2022 20:35:07 +0000 (20:35 +0000)
commit360e1b8197b78685cf08ab5914aa629fb739b2c3
tree685df3a0f7eadbfb6891550e0c9071e7fc682bba
parent41f485b9a7d8fd647c415be1d11b612063dff21c
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>
15 files changed:
src/cmd/compile/internal/types2/instantiate.go
src/cmd/compile/internal/types2/issues_test.go
src/cmd/compile/internal/types2/predicates.go
src/cmd/compile/internal/types2/testdata/check/issues.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50646.go2
src/cmd/compile/internal/types2/unify.go
src/go/types/instantiate.go
src/go/types/issues_test.go
src/go/types/predicates.go
src/go/types/testdata/check/issues.go2
src/go/types/testdata/fixedbugs/issue50646.go2
src/go/types/unify.go
test/typeparam/issue48276a.go
test/typeparam/issue48276a.out
test/typeparam/issue50646.go [deleted file]