return
as an expression
#3052
Labels
feature
Proposed language feature that solves one or more problems
state-duplicate
This issue or pull request already exists
The motivation for this is that I'd love to be able to return from a
switch
expression. i.e.:Since
return
introduces a statement rather than expression, this isn't possible. I see in the language spec that thatthrow
is an expression, makingswitch(x) { _ => throw 'foo' }
legal. Is there a motivation for supportingthrow
and not other control flow keywords? In particular, I'm thinkingreturn
,yield
,continue
,break
, andrethrow
. Maybe it'd be easy to redefine these as expressions, which would be backwards compatible given that Dart already has an expression statement.For a relatively mainstream language that has pattern matching and treats
continue
,break
, andreturn
as expressions, we can look at Rust's expression grammar.(One other thing I'll point out with the introduction of switch expressions is that I'd love to run arbitrary groups of statements in an expression; something like #132)
The text was updated successfully, but these errors were encountered: