-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Update pattern-variables.md #5781
Conversation
@jcouv Does this address your comment #4592 (comment)? |
Note: I think that could be done if we enforce the redeclaration in terms of definite-assignment instead of relying on a declarator. This way the switch example works as presented. That would also result in no error for something like |
I had a similar thought earlier, I think it's a good change that would be well received by LDM. |
This all seems much more complicated than I was envisioning for rules, particularly the in-pattern ones. What I was envisioning was simply: if a variable is not currently definitely assigned, it may be redeclared in a pattern. This would permit |
If I recall correctly, LDM didn't support redeclaration across expression boundaries. I can readd the open question on that.
I only reverted the initial PR and made some changes (this currently mirrors the prototype). |
Right, we were leary of the complex rules involved and concerned about double assignments. I think that my proposed simplification, where it's just "you can assign if it's not definitely assigned", is much simpler and alleviates the double assignment concerns.
My main thought is to simply remove all the things about where variables are allowed to be redeclared in patterns, and simply state that variables are allowed to be redeclared by patterns if they are not definitely assigned and the types all line up. We might have to define what definite assignment means inside a pattern, but I think that's much more straightforward than the existing wording of the rules around where in patterns variables are allowed to be redeclared. |
Just to make sure we're on the same page, "you can assign if it's not definitely assigned" means pattern variables can be effectively redeclared anywhere within their scope; permitting For binary patterns, we need to somehow flow the def assignment state from LHS so that the variables are considered assigned in the RHS (similar to expressions) to catch both That doesn't prevent |
Yes.
Yes
Indeed. I don't especially care about that scenario: you can't use |
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 like this version a lot more :). Just a couple small comments.
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.
@jcouv please take a look
Good to merge. |
Prototype: dotnet/roslyn#59702
Rendered: pattern-variables.md