Closed Levi-Lesches closed 5 months ago
Given that
throw error
is allowed, I'm still not sure whyrethrow
shouldn't be.
It's a language limitation. The bodies of switch expressions are expressions. Many years ago, we made throw
an expression (mainly so you could use it as the body of =>
-bodied methods), but we never turned rethrow
into an expression. We probably should: https://github.com/dart-lang/language/issues/3097.
I think the lint should appear in this case. It (currently) requires you to rewrite the switch, but you probably should do that, so that the error is rethrown with the correct stack trace.
But we should make rethrow
an expression. And return
, break
and continue
too, because we can.
Describe the issue
Rethrowing is supported in switch statements, but not switch expressions.
However, the lint still suggests to replace
throw error
withrethrow
To Reproduce
Expected behavior The lint should not appear.
Additional context Given that
throw error
is allowed, I'm still not sure whyrethrow
shouldn't be. cc @munificent from the linked issue.