-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Generic parameters now can constrain statics in type definitions #19362
Conversation
resolved regression with generic procedures
@@ -1739,11 +1739,22 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, | |||
let prev = PType(idTableGet(c.bindings, f)) | |||
if prev == nil: | |||
if aOrig.kind == tyStatic: | |||
if f.base.kind != tyNone: | |||
if f.base.kind notin {tyNone, tyGenericParam}: | |||
result = typeRel(c, f.base, a, flags) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this line not good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe my other comment should answer this.
result = typeRel(c, f.base, a, flags) | ||
if result != isNone and f.n != nil: | ||
if not exprStructuralEquivalent(f.n, aOrig.n): | ||
result = isNone | ||
elif f.base.kind == tyGenericParam: | ||
# Handling things like `type A[T; Y: static T] = object` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These things should have been taken care of by the line:
result = typeRel(c, f.base, a, flags)
Already. This solution of yours is very good in that it improves the current situation, but it's an ad-hoc bandaid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The information is lost in the future steps so eventually it gets T
vs. T
which is ok to solve with a change to the tyTypedesc
branch, but it then gets typedesc[int]
vs. int literal (2)
without knowing either side is static. Seems the only place to solve it is inside the tyStatic
anywhere lower just lacks the knowledge to know to check the children types. Solving the typedesc[int]
vs. int literal
just causes a bunch of issues with other generics for obvious reasons that values equate types. There very well might be a better solution, I've combed over typerel trying to find it but just hit that wall of lack of information to reason the relation.
…-lang#19362) * Parameters now can constrain static in type definitions resolved regression with generic procedures * Update compiler/sigmatch.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
) * Parameters now can constrain static in type definitions resolved regression with generic procedures * Update compiler/sigmatch.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> (cherry picked from commit a93f6e7)
Prior to this the types were not capable of being instantiated.
Partially addresses #7209 though the following still errors