-
Notifications
You must be signed in to change notification settings - Fork 86
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
C# 7.x: Unifying treatment of discards and local variables in patterns, deconstruction and out variables #561
Comments
As Mads is otherwise occupied for a while, and I have the time, I’ve been working on this issue. I’m starting with discards, and then will look at local variable declarations. Thus far
Next, I need to
My thinking is to then
|
I've created PR 596 to add discards as a separate feature. I've revised PR 44, as follows:
|
I've completed the discard spec part. After looking at the local-variable-creation aspect, I have the following to report: [The use of Out VariableType is optional argument_value
: 'out' local_variable_type? identifier
;
local_variable_type
: type
| 'var'
; If type/ If type/ PatternType is required declaration_pattern
: type identifier
;
var_pattern
: 'var' identifier
;
Tuple DeconstructionType is optional destination
: local_variable_type? identifier
; If type/ If type/ CommentaryAs shown in the descriptions above, the “out variable” and “tuple deconstruction” cases have equivalent syntax and the same semantics, but the “pattern” case is different. The syntax for local variables is defined in §12.6, “Local variable declarations.” However, that context also allows for the declaration of multiple identifiers as well as initializers, things not allowed in the cases above. And in §12.9.5, “The @MadsTorgersen, are you able to take ownership of this again? |
Thanks so much for the work you've done on this, @RexJaeschke! I've blocked time on my calendar to try to bring it all together before the November meeting. |
Fixed in #664 |
Pattern, deconstruction expressions and out variables all allow for local variables to be declared in places that are not accounted for by existing scope rules. In addition, those locations allow for the use of discards in lieu of existing or fresh variables.
Currently the treatment of these variables is spread out and partially duplicated across #61, #63 and #44. I think there's both an opportunity and a need for unifying this treatment, quite possibly introducing new concepts/terms in the process.
Perhaps the best approach is to treat this as a separate "feature" with its own PR, which the above PRs can then build on. The "feature" introduces new concepts (e.g. discards), scope rules etc. but does not in and of itself surface them in syntax.
The text was updated successfully, but these errors were encountered: