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

spec: restriction on self-referential types does not match accepted proposal #63149

Open
bcmills opened this issue Sep 21, 2023 · 0 comments
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@bcmills
Copy link
Contributor

bcmills commented Sep 21, 2023

What did you do?

Write Go programs corresponding to the interfaces illustrated in Fig. 5 and Fig. 7 of Featherweight Go:

Figure 5: https://go.dev/play/p/pkXtATz0zJW?v=gotip
Figure 7: https://go.dev/play/p/w1ULe7lazaT?v=gotip

What did you expect to see?

Behavior per the design described in https://go.dev/design/43651-type-parameters and accepted in #43651:

A generic type can refer to itself in cases where a type can ordinarily refer to itself, but when it does so the type arguments must be the type parameters, listed in the same order. This restriction prevents infinite recursion of type instantiation.

Or, an accepted proposal modifying the design, including a discussion of the tradeoffs involved.

What did you see instead?

invalid recursive type errors.

It appears that what was actually implemented (and what is described in the current spec) does not match what was accepted in the proposal. The spec text was changed to:

Within a type parameter list of a generic type T, a type constraint may not (directly, or indirectly through the type parameter list of another generic type) refer to T.

That breaks the examples from Figure 5 and Figure 7 of the paper, and results in an implementation of type parameters weaker than what was proposed.

For comparison, if the type parameters are removed, both figures compile:
Figure 5 (parameter removed from Eq): https://go.dev/play/p/DKHGVraxMRX?v=gotip
Figure 7 (parameters removed from Edge and Vertex): https://go.dev/play/p/YVxG0BOQgqm?v=gotip

(CC @ianlancetaylor @griesemer)

@bcmills bcmills added the compiler/runtime Issues related to the Go compiler and/or runtime. label Sep 21, 2023
@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 25, 2023
@mknyszek mknyszek added this to the Backlog milestone Oct 4, 2023
@bcmills bcmills added the generics Issue is related to generics label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. generics Issue is related to generics NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

4 participants