]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: eagerly check that constraints are not type params
authorRobert Findley <rfindley@google.com>
Thu, 23 Dec 2021 15:33:17 +0000 (10:33 -0500)
committerRobert Findley <rfindley@google.com>
Thu, 6 Jan 2022 19:12:42 +0000 (19:12 +0000)
commit7a3a2b18ff3b8591eba18b730da7f84751bbfdc5
tree19dd3cd8df34f65077741d150c98a3ee0b977be1
parentf0099106254e288db62de3e3b030915af7decc25
go/types, types2: eagerly check that constraints are not type params

As a result of the change to the underlying of a type parameter to be
its constraint interface, we had couple inaccuracies that combined to
cause an infinite recursion when type checking the invalid type
parameter list [A A].
 - We deferred tpar.iface() using check.later twice: once in
   newTypeParam, and then again at the end of collectTypeParams.
 - We deferred the check that type parameter constraints are not type
   parameters, even though this is unnecessary: the constraint type is
   known.

With these inaccuracies, tpar.iface() was executing before our guard
against using type parameters as constraints, causing an infinite
recursion through under().

Fix this by eagerly checking whether the constraint is a type
parameter, and marking it invalid if so. Also remove the unnecessary
calls to tpar.iface() at the end of collectTypeParams, as this will
already have been scheduled by newTypeParam.

Fixes #50321

Change-Id: I4eecbecf21656615867cb94be65b520e9e795bd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/374294
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue50321.go2 [new file with mode: 0644]
src/go/types/decl.go
src/go/types/testdata/fixedbugs/issue50321.go2 [new file with mode: 0644]