-
Notifications
You must be signed in to change notification settings - Fork 18k
spec: document that recursive type declarations through type parameters are not permitted #40882
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
I don't think these cases should be permitted but it does seem that the errors generated by the type checker are not ideal. |
We currently report a cycle error here which seems reasonable, but we should review if such code should actually be permitted. |
The error seems very reasonable to me, but it would be good to have the spec explicitly say what's disallowed (or maybe I just couldn't find it). I would assume something like "a type constraint in the definition of a type T may refer to T", parallel to "An interface type T may not embed any type element that is, contains, or embeds T, recursively." (but a bit broader, to ban e.g. |
The type checker now reports
which seems pretty decent. We still need to document restrictions in the spec, though. Changed title accordingly. |
Change https://go.dev/cl/457515 mentions this issue: |
Here's a type:
Currently
go2go
complains with confusing errors; the first declaration fails withRec is not a generic type
(it obviously is) and the equivalenttype Rec[type T Rec] interface{ r(T) }
fails withRec is not an interface
(it also obviously is).I assume this shouldn't be allowed: to know if
Rec[T]
is a valid type forT
to implement, we need to know ifT
implementsRec[T]
, which is circular. But I can't find anything in the draft design that would prohibit it.(playground for convenience)
The text was updated successfully, but these errors were encountered: