Back to Csharplang

Bridging expressions and statements working group meeting - Nov 30, 2022

meetings/working-groups/expressions-statements/ES-2022-11-30.md

latest3.3 KB
Original Source

Bridging expressions and statements working group meeting - Nov 30, 2022

Our agenda was to review proposal issues and make an initial decision on whether or not we wanted to pursue the feature in the short term. We organized the discussion around feature areas and scenarios.

Making things that are currently statements exist as expressions

  • #973 - Declaration expressions This would enable syntax like (var x = 1).ToString().

    Resolution: We felt this is not a feature we will work on in the near term.

  • #1340 - Rethrow expressions This would allow throw in expression contexts, where we currently allow throw ex.

    We will work on this in the near term.

  • #867 - Allow break, return, continue in an expression context This would allow break, return, or continue where we allow throw ex expressions today.

    We think throw was a special case. We think return may be a similar special case. There are identified scenarios where ?? and null checks might immediately return from a method. We're less sure about break and continue. We need to see scenarios where those would be compelling. Those may not be added now.

  • Allow any statement to appear as an expression There isn't an issue for this. We added it to the discussion as a logical extension. We don't see a compelling scenario for investing in this at this time.

Modernizing older syntax

These centered on the different structures of the switch statement and switch expression.

There are two alternative for bringing the switch expression and statement syntax closer together:

  • #3038 - Revamping switch statements to reflect switch expression syntax This would allow switch statements to use some of the syntax for switch expressions.
  • #2632 - Allow a switch expression as a statement expression This can be thought of as the inverse of #3038. It would allow a switch expression to be a statement-expression (or a void returning statement).

We're interested in pursuing this in the near term. We're not sure if these are mutually exclusive, or which would be more useful.

Allowing sequences of operations in place of a single expression

These are are very similar, each being a different syntax with potentially different things allowed inside the syntax, but they're all similar in concept.

  • #377 - This is most similar to let bindings in Lisp. Most restrictive of the proposals, it doesn't allow things like foreach
  • #3086 - More general than #377, allows any statement before the final expression.
  • #3037 - A more specific version of #3086, it only expands the syntax for switch expressions

Of these, the only one we're interested in pursuing in the near term is #3037

Overall, of this set, we are interested in these three items:

  1. Allowing switch expressions to be statement expressions
  2. Coalescing switch expression and switch statement syntax
  3. Allowing multi-line arms in a switch expression.