Skip to content

Assignment and discards #1630

Description

@BillWagner

Follow up on #1608 (comment)

During the April 08 committee meeting, we merged #1608 and agreed to this follow up issue.

This new text has issues:

The simple_assignment and compound_assignment expressions assign a new value to a variable, a property, or an indexer element. Event assignment (§12.23.5), a subset of compound_assignment, assigns a new value to an event. The ref_assignment expression assigns a variable reference (§9.5) to a reference variable (§9.7). The deconstructing_assignment assigns values to zero or more variable_references.

We think we should separate discards from variable_references in text. That would enable us to use the number of LHS arguments more clearly. Here's why:

  1. A simple_assignment can assign zero variable_references: _ = M(); The method M must be called to preserve any side-effects, but no variable_references are assigned.
  2. This isn't a deconstructing assignment: It's a simple assignment with parentheses around the discard: (_) = thing;
  3. Ref assignment can assign the ref to a discard: _ = ref Func();

A bit of wordsmithing is necessary, but it should the following:

  1. A discard can't be the left argument of a compound_assignment.
  2. The simple_assignment and ref_assignment assign a single value, as long as the left argument is a variable_reference. In other words, not a discard.
  3. The deconstructing_assignment assign two or more values, as long as the corresponding element on the left side is a variable_reference, not a discard.

The expression on the right side of a simple_assignment and deconstructing_assignment even when the corresponding target is a discard.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions