-
Notifications
You must be signed in to change notification settings - Fork 790
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
Fix a few AND operator parser bugs and regressions #17113
Conversation
❗ Release notes required
|
Hey I am getting a bit desperate with this, whatever I do breaks either pattern matching (the original regression) or constraint intersection (the original feature). I feel I am somewhere close but missing something obvious since I haven't properly worked with the parser before. The current version is the closest I've got so far - it fixes the regression but partially breaks the constraint intersection, in particular this fails to identify the first hash constraint out of multiple hash constraints. E.g. for
this will identify Any ideas, maybe @auduchinok or @kerams? |
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.
Would it make sense to define something like this separately:
hashConstraint:
| HASH atomType
{ SynType.HashConstraint($2, lhs parseState) }
and then use hashConstraint
in place of HASH atomType
here:
Lines 6215 to 6217 in 32e2822
atomType: | |
| HASH atomType | |
{ SynType.HashConstraint($2, lhs parseState) } |
and here:
Lines 5995 to 6000 in 32e2822
intersectionType: | |
| typar AMP intersectionConstraints %prec prec_no_more_attr_bindings // todo precedence | |
{ let constraints, mAmpersands = $3 | |
SynType.Intersection(Some $1, List.rev constraints, lhs parseState, { AmpersandRanges = rhs parseState 2 :: List.rev mAmpersands }) } | |
| HASH atomType AMP intersectionConstraints %prec prec_no_more_attr_bindings // todo precedence |
and in place of atomType
here (with the recovery/error-reporting adjusted accordingly):
Lines 2581 to 2596 in 32e2822
intersectionConstraints: | |
| intersectionConstraints AMP atomType %prec prec_no_more_attr_bindings // todo precedence | |
{ let constraints, mAmpersands = $1 | |
match $3 with | |
| SynType.HashConstraint _ -> () | |
| ty -> errorR(Error(FSComp.SR.parsConstraintIntersectionSyntaxUsedWithNonFlexibleType(), ty.Range)) | |
($3 :: constraints), (rhs parseState 2 :: mAmpersands) } | |
| atomType | |
{ match $1 with | |
| SynType.HashConstraint _ -> () | |
| ty -> errorR(Error(FSComp.SR.parsConstraintIntersectionSyntaxUsedWithNonFlexibleType(), ty.Range)) | |
[ $1 ], [] } |
?
@brianrourkeboll first of all - thanks for jumping in :) (this was meant to be sent on Tuesday but somehow didn't post here) Secondly, the approach you suggest seems to do the job! |
Okay this is green finally :) |
I think this approach should work — as long as we never need to extend the intersection type syntax to allow anything other than flexible types. |
tests/FSharp.Compiler.ComponentTests/Conformance/PatternMatching/And/andPattern04.fs
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
I would guess that the second change here, from intersectionType:
- | typar AMP intersectionConstraints %prec prec_no_more_attr_bindings // todo precedence
+ | typar AMP intersectionConstraints %prec prec_no_more_attr_bindings
{ let constraints, mAmpersands = $3
SynType.Intersection(Some $1, List.rev constraints, lhs parseState, { AmpersandRanges = rhs parseState 2 :: List.rev mAmpersands }) }
- | atomType AMP intersectionConstraints %prec prec_no_more_attr_bindings // todo precedence
+ | hashConstraint AMP intersectionConstraints %prec prec_no_more_attr_bindings
{ let constraints, mAmpersands = $3
SynType.Intersection(None, $1 :: List.rev constraints, lhs parseState, { AmpersandRanges = rhs parseState 2 :: List.rev mAmpersands }) } |
@edgarfgp looks like it does fix that one as well! I will add more tests then, thanks for pointing out :) |
Awesome to finally tackle all of these issues. |
(auto merge had some error, merged manually) |
Fixes #16447
Fixes #17134
Fixes #16309
The problem was introduced together with the constraint intersection support here. The parser no longer stops at the ampersand sign in the clause and tries to interpret :? as part of the type.
Checklist