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

go/types, types2: avoid infinitely recursive instantiation through method signatures #48703

Closed
findleyr opened this issue Sep 30, 2021 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

We've recently started instantiating methods on instantiated types, to simplify their API. However, this introduces an infinite recursion in cases like this:

package p
type List[P any] struct{}
func (_ List[P]) m() (_ List[List[P]]) { return }

This is similar to #48098, but will require a different fix; we need to allow these types of methods to be written.

I think there is a straightforward fix: we already have a lazy resolution mechanism for Named types, and can use it to expand methods lazily the first time they are accessed (see also #47910). We just need to allow types to escape the type-checking pass with their methods unexpanded, which is a bit subtle.

CC @griesemer

@findleyr findleyr added this to the Go1.18 milestone Sep 30, 2021
@findleyr findleyr self-assigned this Sep 30, 2021
@findleyr findleyr added the NeedsFix The path to resolution is known, but the work has not been done. label Sep 30, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/354639 mentions this issue: go/types: only resolve underlying if

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/356490 mentions this issue: go/types: ensure named types are expanded after type-checking

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/356515 mentions this issue: cmd/compile/internal/types2: ensure named types are expanded after type-checking

gopherbot pushed a commit that referenced this issue Oct 19, 2021
…pe-checking

This is a clean port of CL 356490 from go/types to types2.

Fixes #48703.
Fixes #48974.

Change-Id: I08c0db0b92250cbb043325541b21a577726b40ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/356515
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants