carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Should the wide arrow in match-case be dropped?

Open CJ-Johnson opened this issue 8 months ago • 5 comments
trafficstars

Summary of issue:

New Information: The syntax for match-case was chosen before the syntax of lambdas was designed. Since then, lambdas landed in the language in #3848. This means the syntax of lambdas could potentially justify reconsidering the syntax of match-case.

Issue: The arrow in a case of match-case uses the => syntax followed by a curly braced body. This is incongruent to the syntax of all function kinds, with the lambdas proposal landed. The "wide arrow" means a function returns auto deduced from a single-expression body followed by a semicolon.

Leads Question: Would it be ok to drop the wide arrow entirely from the match-case syntax? Assuming the parens are mandatory regular parens, as suggested in #5118, there shouldn't be any syntactic ambiguities if match-case was written like the following:

match (F()) {
  // Notice the lack of wide arrow
  case (x: auto) {
    // ...
  }
}

Details:

No response

Any other information that you want to share?

No response

CJ-Johnson avatar Mar 12 '25 22:03 CJ-Johnson