Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types2, go/types: missing errors for invalid parameterized type declarations #48962

griesemer opened this issue Oct 14, 2021 · 2 comments


Copy link

@griesemer griesemer commented Oct 14, 2021

This is a new version of frozen #39938. The following code

package p

type T0[P any] struct {
        f P

type T1 struct { // <<< should get a cycle error here
        _ T0[T1]

is invalid because T1 would expand indefinitely. The previous fix ( could lead to infinite sequences of instantiations (see #48951).

Correct solution of this problem requires some form of type flow analysis and is related to (and may be addressed with) #48098.

@griesemer griesemer added this to the Go1.18 milestone Oct 14, 2021
@griesemer griesemer self-assigned this Oct 14, 2021
Copy link

@gopherbot gopherbot commented Oct 14, 2021

Change mentions this issue: cmd/compile/internal/types2: avoid infinite expansion for invalid recursive generic types

Copy link
Contributor Author

@griesemer griesemer commented Oct 14, 2021

cc: @findleyr

gopherbot pushed a commit that referenced this issue Oct 14, 2021
…ursive generic types

The algorithm for detecting invalid recursive types that
expand indefinitely suffered from the exact problem is was
intended to detect: if the indefinite expansion is happening
through type parameters, the algorithm ended up in an infinite
sequence of instantiations. (This is only a problem for generic

Changed the algorithm to always only consider the "original"
uninstantiated types. This avoids the problem but it will also
not detect some invalid recursive generic types anymore. That
requires a more sophisticated type flow analysis.
Opened #48962 to track.

Addressed with help from @findleyr.

For #48951.

Change-Id: Ie29cea8f810dae55153dbb1b17c9390cd823c2d9
Trust: Robert Griesemer <>
Reviewed-by: Robert Findley <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants