]> Cypherpunks.ru repositories - gostls13.git/commit
go/types: ensure named types are expanded after type-checking
authorRobert Findley <rfindley@google.com>
Fri, 15 Oct 2021 20:39:39 +0000 (16:39 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 18 Oct 2021 22:55:32 +0000 (22:55 +0000)
commit323e009c757229bdf58f68fde1c5bf07e9e65b61
tree3132a1fe9c4d8bdd004e5f5d8a979f6796268fac
parent73971784dc586a5db3b81dfdd41954f650d493ac
go/types: ensure named types are expanded after type-checking

Rather than using Checker.later in newNamed, add a Checker.defTypes
field to track named types that have been created during type-checking,
and use this to expand named types as a final phase in type checking.

We have encountered several bugs related to infinite recursion while
expanding named types, because (I would argue) we have two conflicting
requirements in the type checker: ensuring that we eventually collapse
underlying chains, and yet allowing lazy substitution of the underlying
type in instances. The former is necessary for correctness, and to
ensure that we detect cycles during the type-checking pass. The latter
is necessary to allow infinitely expanding patterns of instances through
underlying or method definitions.

I believe this CL reconciles these conflicting requirements, by creating
a boundary between types that are encountered in the source during
type checking, and instances that are created by recursive evaluation.
At the end of the type checking pass, Checker.defTypes should contain
all possible origin types for instantiation. Once we compute the true
underlying for these origin types, any remaining instances that are
unresolved are guaranteed to have an origin with a valid underlying.
Therefore, we can return from the type-checking pass without calling
under() for these remaining instances.

Fixes #48703
Fixes #48974

Change-Id: I1474f514e2ab71c1ad4c3704fe32bfba11d59394
Reviewed-on: https://go-review.googlesource.com/c/go/+/356490
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/check.go
src/go/types/named.go
src/go/types/testdata/fixedbugs/issue48703.go2 [new file with mode: 0644]
src/go/types/testdata/fixedbugs/issue48974.go2 [new file with mode: 0644]