-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: erroneously accepts recursive type aliases #25141
Comments
Tangentially, I'm questioning what the fundamental difference (if any) is between We sorta support the latter, but it's sketchy and a recurring thorn. I think if we properly fix support for it, it would make supporting the former trivial. But maybe it's just better to disallow both. |
Looks the difference is whether or not the declaration is an alias declaration. |
Somewhat related: #23139 . go/types has issues with detecting certain cycles. I hope to address this for 1.11. Per the original type-alias design doc from @rsc, it must be possible to "expand out" type alias declarations; this wouldn't be possible for I think it would be nice to accept all these, but our depth-first based type-checking approaches have troubles with them; and ad-hoc approaches tend to be incorrect. We need to either disallow these cases or have a sound way to describe what we allow and what we don't, and also a (understood and correct) way of type-checking them w/o incurring undue cost. At the same time, these are probably not urgent. |
Change https://golang.org/cl/114517 mentions this issue: |
Change https://golang.org/cl/115455 mentions this issue: |
The existing code explicitly passes a (type name) path around to determine cycles; it also restarts the path for types that "break" a cycle (such as a pointer, function, etc.). This does not work for alias types (whose cycles are broken in a different way). Furthermore, because the path is not passed through all type checker functions that need it, we can't see the path or use it for detection of some cycles (e.g. cycles involving array lengths), which required ad-hoc solutions in those cases. This change introduces an explicit marking scheme for any kind of object; an object is painted in various colors indicating its state. It also introduces an object path (a stack) main- tained with the Checker state, which is available in all type checker functions that need access to it. The change only introduces these mechanisms and exercises the basic functionality, with no effect on the existing code for now. For #25141. Change-Id: I7c28714bdafe6c8d9afedf12a8a887554237337c Reviewed-on: https://go-review.googlesource.com/114517 Reviewed-by: Alan Donovan <adonovan@google.com>
18130-type-alias explicitly states that
type T = *T
is invalid, but go/types accepts it:cmd/compile does not.
Notably though, I don't see any wording in the text actually added to the Go spec that precludes this.
/cc @griesemer
The text was updated successfully, but these errors were encountered: