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
Use Pattern matching in ast.cs #18794
Conversation
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 would prefer to see a PR that utilises IDE0019 code fix to avoid logic errors.
| var subExpr = this as SubExpressionAst; | ||
|
|
||
| if (parenExpr == null && subExpr == null) | ||
| if (this is not ParenExpressionAst or SubExpressionAst) |
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.
Logic error
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.
@MartinGC94 Please address the comment.
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 for the catch @xtqqczze
Looking a bit more at that if statement, isn't it completely pointless? NewInvalidOperationException creates a new exception ready to be thrown but here it's neither thrown nor saved to a variable so it can be thrown later on.
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.
@MartinGC94 Please open new issue.
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.
Issue opened: #18812
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.
@MartinGC94 For future reference, logical patterns can use parentheses, e.g. this is not (ParenExpressionAst or SubExpressionAst).
Co-authored-by: Ilya <darpa@yandex.ru>
…werShell into UsePatternMatching
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? |
|
Contributes to #18399. |
|
Handy links: |
PR Summary
Replace unnecessary variable assignments that use "as" with inline "is" statements in various if statements.
PR Context
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.(which runs in a different PS Host).