-
Notifications
You must be signed in to change notification settings - Fork 789
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
Parens: handle special parsing of new T…
& inherit T…
#16239
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* Ctor applications are handled differently in the parser after the `new` and `inherit` keywords than they are elsewhere: only a subset of expressions are allowed as an argument (as specified in `atomicExprAfterType` in pars.fsy). This means that any expression outside of that blessed subset must be parenthesized, even if the exact same ctor application would not require parentheses without `new` or `inherit`.
I have a fear that relaxing this altogether would lead to a lot more parser issues, especially w.r.t to parser precedence rules and type arguments. let x = new (int A)(new (int B)(new (int C)))) When you tried to change the parser to accommodate this, all test suites including FsharpQA ran without issue? |
T-Gro
approved these changes
Nov 8, 2023
psfinaki
approved these changes
Nov 8, 2023
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.
Thanks, great!
brianrourkeboll
changed the title
Handle special parsing of
Parens: handle special parsing of Nov 12, 2023
new T…
& inherit T…
new T…
& inherit T…
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Followup to #16079.
new
orinherit
keywords.Constructor applications are handled differently in the parser after the
new
andinherit
keywords than they are elsewhere: only a subset of expressions are allowed as an argument (as specified inatomicExprAfterType
in pars.fsy). This means that any expression outside of that blessed subset must be parenthesized, even if the exact same ctor application would not require parentheses withoutnew
orinherit
.E.g.,
This is due to the following in pars.fsy:
fsharp/src/Compiler/pars.fsy
Line 4841 in 24ef671
fsharp/src/Compiler/pars.fsy
Line 5336 in 24ef671
fsharp/src/Compiler/pars.fsy
Lines 5042 to 5076 in 24ef671
These are required to support the use of postfix generic notation in those contexts (as noted in #16239 (comment)) and possibly other things. Even though the use of postfix notation in such contexts seems likely to be quite rare on the whole, removing support for it would be a breaking change.
Edit: click to see the question that was answered in the comments
Question for those in the know
(I can open a new issue for this if it makes sense.)
I've run into this inconsistency repeatedly over the years and it has always bothered me. Is the
atomicExprAfterType
restriction here actually still needed? Would that suddenly cause more problems like those addressed by #15923? Or could we just replace it withargExpr
in the parser fornew
andinherit
and get rid of the inconsistency? Making that change locally seems to work and doesn't seem to cause any immediate problems in this codebase......Ideally
new ctor expr
andctor expr
would be completely interchangeable (except, probably, in object expressions), but there is one additional inconsistency that would require more changes to the compiler to resolve. Explicit type arguments are required when the application is preceded bynew
but can be inferred whennew
is not present:ResizeArray 3
is allowed, butnew ResizeArray (3)
is not (regardless of parentheses around the arg).