Skip to content
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

Add discard feature #596

Closed
wants to merge 8 commits into from
Closed

Add discard feature #596

wants to merge 8 commits into from

Conversation

RexJaeschke
Copy link
Contributor

@RexJaeschke RexJaeschke commented Jun 19, 2022

This PR addresses the discard part of Issue #561 as well as the use of a discard on the lhs of simple assignment, which was previously covered by PR #44. That text will be removed from PR 44, and that PR will be revised to reflect PR 596's existence.

I have yet to review PR #61 or #63 in terms of this new PR. When I eventually do so, I might need to come back and tweak this PR.

The local-variable creation part of Issue #561 will be addressed separately.

@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Jun 19, 2022
@RexJaeschke RexJaeschke added this to the C# 7.x milestone Jun 19, 2022
@RexJaeschke RexJaeschke self-assigned this Jun 19, 2022
@RexJaeschke RexJaeschke marked this pull request as draft June 19, 2022 20:23
Copy link
Contributor

@Nigel-Ecma Nigel-Ecma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine, my two comments are just optional suggestions on presentation not content.

@@ -5678,7 +5678,7 @@ assignment_operator

The left operand of an assignment shall be an expression classified as a variable, a property access, an indexer access, or an event access.

The `=` operator is called the ***simple assignment operator***. It assigns the value of the right operand to the variable, property, or indexer element given by the left operand. The left operand of the simple assignment operator shall not be an event access (except as described in [§14.8.2](classes.md#1482-field-like-events)). The simple assignment operator is described in [§11.18.2](expressions.md#11182-simple-assignment).
The `=` operator is called the ***simple assignment operator***. When the left operand is not a discard (§discards-new-clause), this operator assigns the value of the right operand to the variable, property, or indexer element given by the left operand. Otherwise, the right operand is evaluated with its value being discarded. The left operand of the simple assignment operator shall not be an event access (except as described in [§14.8.2](classes.md#1482-field-like-events)). The simple assignment operator is described in [§11.18.2](expressions.md#11182-simple-assignment).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it more obvious that the right operand is always evaluated by stating that first? Something along the lines of:

The = operator is called the simple assignment operator. This evaluates the right operand and then either: assigns the value to the variable, property, or indexer element given by the left operand; or discards the value if the left operand is a discard (§discards-new-clause). The left operand of the simple assignment operator shall not be an event access (except as described in §14.8.2). The simple assignment operator is described in §11.18.2.


Under certain circumstances, a discard may be used in the same scope as an explicitly declared variable named `_`.

For details of using discards when deconstructing tuples, see §deconstruction-expressions-new-clause. When calling methods with `out` parameters, see [§14.6.2.4](classes.md#14624-output-parameters). In a pattern-matching operation with the `is` and `switch` statements, see [§11.11.11](expressions.md#111111-the-is-operator) and [§12.8.3](statements.md#1283-the-switch-statement), respectively. As the left operand of a simple assignment, see [§11.18.2](expressions.md#11182-simple-assignment).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a list, textual or bullets? This is just changing punctuation but might be clearer, e.g.

For details of using discards: when deconstructing tuples, see §deconstruction-expressions-new-clause; when calling methods with out parameters, see §14.6.2.4; in a pattern-matching operation with the is and switch statements, see §11.11.11 and §12.8.3, respectively; and as the left operand of a simple assignment, see §11.18.2.

or

For details of using discards:

  • when deconstructing tuples, see §deconstruction-expressions-new-clause;
  • when calling methods with out parameters, see §14.6.2.4;
  • in a pattern-matching operation with the is and switch statements, see §11.11.11 and §12.8.3, respectively; and
  • as the left operand of a simple assignment, see §11.18.2.

@BillWagner BillWagner force-pushed the add-discard-feature branch from ed10ff9 to c3b3d9f Compare October 2, 2022 22:22

Under certain circumstances, a discard may be used in the same scope as an explicitly declared variable named `_`.

For details of using discards when deconstructing tuples, see §deconstruction-expressions-new-clause. When calling methods with `out` parameters, see [§14.6.2.4](classes.md#14624-output-parameters). In a pattern-matching operation with the `is` and `switch` statements, see [§11.11.11](expressions.md#111111-the-is-operator) and [§12.8.3](statements.md#1283-the-switch-statement), respectively. As the left operand of a simple assignment, see [§11.18.2](expressions.md#11182-simple-assignment).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing the build issue. The deconstruction-expression-new-clause isn't resolving.

@RexJaeschke RexJaeschke removed their assignment Dec 6, 2022
Where to describe discards in the spec? I don’t think it warrants being in the “Basic concepts” chapter. The “Variables” chapter looks like the best fit. My initial thought was to make discards a new variable category. However, as a discard is a pseudo-variable, my current thinking is to describe it in a new top-level section in the variables chapter. Basically, we don’t want to have to change any existing prose w.r.t variables to exclude discards. Better to make them sort-of-but-not-quite-variables! And while a variable name is a *variable_reference*, a discard is not.
@BillWagner
Copy link
Member

Closed in favor of #664

@BillWagner BillWagner closed this Apr 20, 2023
@RexJaeschke RexJaeschke deleted the add-discard-feature branch June 9, 2023 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Review: pending Proposal is available for review type: feature This issue describes a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants