dart-lang / dart-lang/language
Can't `rethrow` in switch expression
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Shouldn't be possible to `rethrow` in a switch expression since we can `throw e`?
Random example:
```dart
void main() {
try {
// some code that might throw
} catch (e) {
return switch (e) {
Exception() => print('Return what this function asks for (void).'),
Error() => throw e, //Works, but warning "Use 'rethrow' to rethrow a caught exception."
_ => rethrow, // Error "Undefined name 'rethrow'"
};
}
}
```
Inside a `catch` clause I think we could allow a `rethrow` statement.
Contributor guide
Research direction
Start with the Dart language specification rules for catch clauses, rethrow, and switch expressions, using the example in the issue as the motivating case. Trace how the expression is analyzed inside a catch clause and define the intended language and diagnostic behavior; done means the specification change and its edge cases are agreed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100