]> Cypherpunks repositories - gostls13.git/commit
cmd/compile/internal/types2: accept constraint literals with elided interfaces
authorRobert Griesemer <gri@golang.org>
Thu, 30 Sep 2021 03:56:36 +0000 (20:56 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 1 Oct 2021 17:18:34 +0000 (17:18 +0000)
commitdab16c1c90626ca6c9704959500f120fd09546e6
treec8ce62f8ae4d74ae478f5bb7825279f4db1431f8
parent5279e534b5ced1eaea19e8b75968498287ff6228
cmd/compile/internal/types2: accept constraint literals with elided interfaces

When collecting type parameters, wrap constraint literals of the
form ~T or A|B into interfaces so the type checker doesn't have
to deal with these type set expressions syntactically anywhere
else but in interfaces (i.e., union types continue to appear
only as embedded elements in interfaces).

Since a type constraint doesn't need to be an interface anymore,
we can remove the respective restriction. Instead, when accessing
the constraint interface via TypeParam.iface, wrap non-interface
constraints at that point and update the constraint so it happens
only once. By computing the types sets of all type parameters at
before the end of type-checking, we ensure that type constraints
are in their final form when accessed through the API.

For #48424.

Change-Id: I3a47a644ad4ab20f91d93ee39fcf3214bb5a81f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/353139
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/testdata/examples/typesets.go2 [new file with mode: 0644]
src/cmd/compile/internal/types2/testdata/fixedbugs/issue39723.go2
src/cmd/compile/internal/types2/typeparam.go
test/typeparam/tparam1.go