-
Notifications
You must be signed in to change notification settings - Fork 18k
types2, go/types: infinite loop typechecking (invalid) recursive generic struct #48951
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
Comments
Thanks. |
Change https://golang.org/cl/355732 mentions this issue: |
Change https://golang.org/cl/355733 mentions this issue: |
I ran into similar problem. Here is the reproducer: type Fooer interface {
Foo()
}
type Fooable[F Fooer] struct {
ptr F
}
func (f *Fooable[F]) Adapter() *Fooable[*FooerImpl[F]] {
return &Fooable[*FooerImpl[F]]{&FooerImpl[F]{}}
}
//
// By removing the 'F Fooer' type param, program compiles sucessfully
// |||||||||
// vvvvvvvvv
type FooerImpl[F Fooer] struct {
}
func (fi *FooerImpl[F]) Foo() {} |
…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 types). 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 Reviewed-on: https://go-review.googlesource.com/c/go/+/355732 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
@jkmpariab Thanks for your report. Your issue is not fixed yet, and may or may not be related to this issue. I've opened #48974 to track it. |
This package sends the type checker into an infinite loop:
/cc @griesemer @findleyr
The text was updated successfully, but these errors were encountered: