-
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
cmd/compile: cyclic constraints are not detected #69589
Comments
Probably related #60817 I tried to understand how the type check happens and the constraint type passed to objDecl is colored black and the check is skipped. Also, type constraints are not named types and hence are not generic. |
I think that it's just that it is unsatisfiable but the compiler doesn't currently check for it (don't know whether it is necessary). The compiler should error out as soon as someone tries to instantiate T2. For instance this would work: https://go.dev/play/p/mIrGf99BVK3 Meaning it depends on T1. |
I don't see any obvious reason that the code in the original post is invalid. |
CC @griesemer |
Finding 1: it will still compile even if
Finding 2:
|
Rethink it for awhile. I think this is the same problem of empty-type-set constraints.
Please read the last section of https://go101.org/generics/777-operations-on-values-of-type-parameter-types.html for details. |
I don't believe this is related to #60817. The compiler does currently report some cycles through type parameter lists, but I believe we're overly restrictive in those cases. As @ianlancetaylor already said, I don't believe there should be an error in this specific case (type parameters renamed to simplify): type T1[_ any] struct{}
type T2[P T1[P]] struct{}
All that said, as long as One might argue that the compiler should report an error because effectively Closing this as working as intended. PS: (*) If |
Go version
1.23.1
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
Program compiles successfully.
What did you expect to see?
error
invalid recursive type C2
.The text was updated successfully, but these errors were encountered: