-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Fix VariablesDeclaredWalker with recursive patterns #80910
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 VariablesDeclaredWalker with recursive patterns #80910
Conversation
src/Compilers/CSharp/Portable/FlowAnalysis/VariablesDeclaredWalker.cs
Outdated
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/FlowAnalysis/VariablesDeclaredWalker.cs
Outdated
Show resolved
Hide resolved
Instead of having a helper that must know how to dive deep into patterns and rely on containing nodes to call it, can we override appropriate Refers to: src/Compilers/CSharp/Portable/FlowAnalysis/VariablesDeclaredWalker.cs:70 in e745150. [](commit_id = e745150, deletion_comment = False) |
|
Done with review pass (commit 2), tests were not looked at. #Closed |
I don't think this could be solved, for example, by only overriding Visit for the specific BoundPattern kinds, which directly contain variables. Instead you would have to declare all the Visit methods for all the pattern subtypes, and write the code to traverse the parts of the patterns which could contain variables. This is because the base type Visit methods already don't do this, to the best of my understanding. I think this approach, as well as the approach in iteration 2, would also end up requiring re-implementing "safe" traversal of binary patterns (because of the need to find variables in A few alternatives I considered:
It's possible I missed something that would make fixing this easier to accomplish. Let me know if you have any further thoughts. |
I guess it would be fine for |
It looks like it is possible to AnalyzeDataFlow with the Expression inside a pattern which takes constant values. I think only in error cases can you declare variables in such expressions, but, I added test |
src/Compilers/CSharp/Test/Emit3/FlowAnalysis/PatternsVsRegions.cs
Outdated
Show resolved
Hide resolved
|
Done with review pass (commit 9) |
| private void NoteDeclaredPatternVariables(BoundPattern pattern) | ||
| { | ||
| if (IsInside) | ||
| switch (pattern) |
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.
This walk is roughly based on DefiniteAssignment.VisitPattern.
AlekseyTs
left a 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.
LGTM (commit 10)
Closes #79489
@CyrusNajmabadi PTAL