]> Cypherpunks repositories - gostls13.git/commit
go/types, types2: don't panic with invalid recursive generic type
authorRobert Griesemer <gri@golang.org>
Sat, 21 May 2022 00:42:40 +0000 (17:42 -0700)
committerRobert Griesemer <gri@google.com>
Tue, 24 May 2022 17:02:34 +0000 (17:02 +0000)
commit70668a4144c27a2100995dbbdbd97b4924cf5e35
tree174a19633766c65f0d66e7e42feeced9c55ab24d
parenteb3ac1f5a471c07a84353ae693024a251db9845f
go/types, types2: don't panic with invalid recursive generic type

Add cycle detection to hasVarType to avoid infinite recursions
caused by invalid cyclic types. This catches cases where the
validType check has not yet run or has checked differently
instantiated types.

As an alternative, validType could mark invalid *Named types
by setting their underlying types to Typ[Invalid]. That does
work but discards information which leads to undesired effects
with other errors. A better mechanism might be to explicitly
track in *Named if a type is invalid and why it is invalid,
and connect that with a general validity attribute on types.
That's a more invasive change we might consider down the road.

Fixes #52915.

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