FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement Null Coalescing and Null Coalescing assignment operators by adityapatwardhan · Pull Request #10636 · PowerShell/PowerShell · GitHub

Implement Null Coalescing and Null Coalescing assignment operators - #10636

Merged
Dongbo Wang (daxian-dbw) merged 24 commits into
PowerShell:masterfrom
adityapatwardhan:NullAssignment
Oct 17, 2019
Merged

Implement Null Coalescing and Null Coalescing assignment operators#10636
Dongbo Wang (daxian-dbw) merged 24 commits into
PowerShell:masterfrom
adityapatwardhan:NullAssignment

Conversation

Aditya Patwardhan (adityapatwardhan) commented Sep 27, 2019
edited
Loading

Copy link
Copy Markdown
Member

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 the TokenFlags 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. The BinaryPrecedenceMask was also changed from 0x07 to 0x0f. 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

Copy link
Copy Markdown
Collaborator

FYI this will clash with Posh-Git that implements an alias of ?? as below

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Alias           ?? -> Invoke-NullCoalescing                        0.7.3      Posh-git

Copy link
Copy Markdown
Collaborator

We've already moved the use of ?? to internal-only in v1 and will happily get rid of it altogether for PS v7.

Rob Holt (rjmholt) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

/// and all of the case sensitive variants of these operators, if they exists.
/// </summary>
BinaryPrecedenceComparison = 3,
BinaryPrecedenceComparison = 0x5,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Since enum's are treated like constants, this would be a breaking change for compiled projects right?

Aditya Patwardhan (adityapatwardhan) Oct 15, 2019
edited
Loading

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Member

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)

Copy link
Copy Markdown
Member

(thanks for opening the issue already!)

Dongbo Wang (daxian-dbw) added the Breaking-Change breaking change that may affect users label Oct 14, 2019

Dongbo Wang (daxian-dbw) left a comment
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM! Now waiting on the breaking change review from the committee.

Dongbo Wang (daxian-dbw) added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Oct 15, 2019

Copy link
Copy Markdown
Member

It just occurred to me that none of the existing ICustomAstVisitor2.VisitBinaryExpression implementation is changed.
Aditya Patwardhan (@adityapatwardhan) did you review all existing VisitBinaryExpression and VisitAssignmentStatement to see if anything needs to be changed? For example, IsConstantValueVisitor might need to be updated for the ?? binary operation, as this operation can be potentially constant value.

Copy link
Copy Markdown
Collaborator

IsConstantValueVisitor might need to be updated for the ?? binary operation, as this operation can be potentially constant value.

It looks like that's just a question of the token flag:

public object VisitBinaryExpression(BinaryExpressionAst binaryExpressionAst)
{
return binaryExpressionAst.Operator.HasTrait(TokenFlags.CanConstantFold) &&
(bool)binaryExpressionAst.Left.Accept(this) && (bool)binaryExpressionAst.Right.Accept(this)
&& !IsNullDivisor(binaryExpressionAst.Right);
}

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) I will review all the existing VisitBinaryExpression and VisitAssignmentStatement to see if anything needs to change. I will submit those changes as part of a different PR.

Copy link
Copy Markdown
Member

@PowerShell/powershell-committee reviewed the changes to TokenFlags and agreed to accept this breaking change. We can revisit this decision if there is new feedback coming in during the use of 7.0.0-preview.5 and 7.0.0-preview.6 of pwsh.

Ilya (iSazonov) added Committee-Reviewed PS-Committee has reviewed this and made a decision and removed Review - Committee The PR/Issue needs a review from the PowerShell Committee labels Oct 17, 2019
Dongbo Wang (daxian-dbw) merged commit 425bc36 into PowerShell:master Oct 17, 2019
Dongbo Wang (daxian-dbw) added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Oct 17, 2019

Copy link
Copy Markdown

🎉v7.0.0-preview.5 has been released which incorporates this pull request.:tada:

Handy links:

This file contains hidden or 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Committee-Reviewed PS-Committee has reviewed this and made a decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL