Open
Conversation
Fixes dotnet#1631 "zero or more variable_references" → "two or more targets" (grammar requires 2+ elements; targets can be variable_references or discards) Adds: compound_assignment LHS shall not be a discard Adds: simple_assignment and ref_assignment LHS may be a discard Adds: RHS is evaluated even when target is a discard, but no value is stored
jskeet
reviewed
Apr 16, 2026
| > *Note*: ANTLR grammar semantics enforce this requirement due to the ordering of the alternatives. *Semantically* there is no overlap between the four alternatives, this is a syntactic disambiguation. | ||
|
|
||
| The *simple_assignment* and *compound_assignment* expressions assign a new value to a variable, a property, or an indexer element. Event assignment ([§12.23.6](expressions.md#12236-event-assignment)), a subset of *compound_assignment*, assigns a new value to an event. The *ref_assignment* expression assigns a variable reference ([§9.5](variables.md#95-variable-references)) to a reference variable ([§9.7](variables.md#97-reference-variables-and-returns)). The *deconstructing_assignment* assigns values to zero or more *variable_reference*s. | ||
| The *simple_assignment* and *compound_assignment* expressions assign a new value to a variable, a property, or an indexer element. Event assignment ([§12.23.6](expressions.md#12236-event-assignment)), a subset of *compound_assignment*, assigns a new value to an event. The *ref_assignment* expression assigns a variable reference ([§9.5](variables.md#95-variable-references)) to a reference variable ([§9.7](variables.md#97-reference-variables-and-returns)). The *deconstructing_assignment* assigns values to two or more targets, where each target is either a *variable_reference* or a discard. The left operand of a *simple_assignment* or *ref_assignment* may also be a discard. The left operand of a *compound_assignment* shall not be a discard. When the left operand of a *simple_assignment* or *ref_assignment*, or a target of a *deconstructing_assignment*, is a discard, the corresponding right-side expression is evaluated but no value is stored. |
Contributor
There was a problem hiding this comment.
Do we want something for the simple assignment at the start of this line too?
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1631
"zero or more variable_references" → "two or more targets" (grammar requires 2+ elements; targets can be variable_references or discards)
Adds: compound_assignment LHS shall not be a discard
Adds: simple_assignment and ref_assignment LHS may be a discard
Adds: RHS is evaluated even when target is a discard, but no value is stored