]> Cypherpunks.ru repositories - gostls13.git/commit
go/types, types2: handle named and literal interfaces in interface unification
authorRobert Griesemer <gri@golang.org>
Fri, 2 Jun 2023 00:20:02 +0000 (17:20 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 6 Jun 2023 14:52:02 +0000 (14:52 +0000)
commit1d3daebc5fd5f51e16fa160a84f8fcfa28b4e2d7
tree19968a775776a55f1179f3c97aca0474fc222e18
parentfd03e6ebc91fb0b6f4dc721a323dc0b408e3b30b
go/types, types2: handle named and literal interfaces in interface unification

If we don't have exact unification, we must consider interface
unification whether one of the types is a defined (named) interface
or not. Otherwise, if one of them is named, and the other one isn't,
the code selects interface-vs-non-interface unification and possibly
uses the wrong method set as the "required" method set, leading to
(incorrect) unification failure as was the case in #60564.

We can also not simply rely on getting this right in the subsequent
switch, through the handling of *Named types.

This CL fixes this simple logic error. If there's inexact unification,
now all (non-type parameter) interface cases are handled in one place,
before the switch. After handling interfaces, we are guaranteed that
we have either no interfaces, or we have exact unification where both
types must be of the same structure.

As a consequence, we don't need special handling for named interfaces
in the *Named case of the switch anymore.

Also, move the (unbound) type parameter swap from before interface
handling to after interface handling, just before the switch which
is the code that relies on a type parameter being in x, if any.

Fixes #60564.

Change-Id: Ibf7328bece25808b8dbdb714867048b93689f219
Reviewed-on: https://go-review.googlesource.com/c/go/+/500195
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/unify.go
src/go/types/unify.go
src/internal/types/testdata/fixedbugs/issue60562.go