-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Implement Null Coalescing and Null Coalescing assignment operators #10636
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
Implement Null Coalescing and Null Coalescing assignment operators #10636
Conversation
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
FYI this will clash with Posh-Git that implements an alias of
|
We've already moved the use of |
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
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.
Really nice that this didn't require any changes to the parser and generally quite contained elsewhere -- feels like a vindication of good code for assignment processing.
Left a few comments.
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
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.
Talked to @adityapatwardhan offline.
After more thoughts, supporting the coalesce operation in binder doesn't really make sense. The operation is so simple that the restriction generated from binder will basically be the same checks we will do if the support is done in compiler directly. So after talking with @adityapatwardhan, we decided to move the implementation back to compiler.
The extended binary operation approach could be useful for a binary operation that is more complex, in case we need another binary operator in future.
|
||
/// <summary> | ||
/// The precedence of comparison operators including: '-eq', '-ne', '-ge', '-gt', '-lt', '-le', '-like', '-notlike', | ||
/// '-match', '-notmatch', '-replace', '-contains', '-notcontains', '-in', '-notin', '-split', '-join', '-is', '-isnot', '-as', | ||
/// and all of the case sensitive variants of these operators, if they exists. | ||
/// </summary> | ||
BinaryPrecedenceComparison = 3, | ||
BinaryPrecedenceComparison = 0x5, |
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.
Since enum's are treated like constants, this would be a breaking change for compiled projects right?
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.
Yes, this will be a breaking change. We are expecting the impact to very small though. I have updated the PR Context in description with more details.
This issue has changes that could potentially change syntax. Please consider adding this feature to EditorSyntax which is used for syntax highlighting in GitHub, Visual Studio Code, Atom, Sublime Text, and many more locations. Consistent syntax highlighting is very important for the language and a feature isn't "complete" until syntax highlighting is what is expected. If you can't contribute to EditorSyntax, at least open an issue to track the work - however, please note, that no one is actively working on the repo and so the work will likely not get done in a timely manner. We hope that you consider contributing to EditorSyntax. (note this is copy/pasted text for any change that looks like it could impact EditorSyntax - and will be a bot in the future) |
(thanks for opening the issue already!) |
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Show resolved
Hide resolved
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Show resolved
Hide resolved
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.
LGTM! Now waiting on the breaking change review from the committee.
src/System.Management.Automation/engine/ExperimentalFeature/ExperimentalFeature.cs
Outdated
Show resolved
Hide resolved
It just occurred to me that none of the existing |
It looks like that's just a question of the token flag: PowerShell/src/System.Management.Automation/engine/parser/ConstantValues.cs Lines 196 to 201 in beb8b44
|
@daxian-dbw I will review all the existing |
@PowerShell/powershell-committee reviewed the changes to |
🎉 Handy links: |
PR Summary
Implement the Null Coalescing
??
and Null Coalescing Assignment??=
operators.PR Context
The operators are discussed in the issue #3240
This PR addresses part of RFC PowerShell/PowerShell-RFC#223
The PR is marked as a
Breaking Change
due to changes in theTokenFlags
enum. The changes were made to include the new TokenFlag -BinaryPrecedenceCoalesce
. While making this change, it was also decided to create more space in the BinaryPrecedence section of the enum for future binary operators. TheBinaryPrecedenceMask
was also changed from0x07
to0x0f
. The order of precedence is not changed. We expected it can cause a breaking change for binary modules as C# treats enums as constants. Though, it is a breaking change we expect the impact to be pretty low as the usage of precedence token flags should be fairly low.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.??
??=
?.
and?[]
operators MicrosoftDocs/PowerShell-Docs#4925??
??=
?.
?[]
operators EditorSyntax#185