dart-lang / dart-lang/language
Exhaustiveness of enums
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
I may be misunderstanding the patterns feature. Should the following code work?
```dart
enum ABC { a, b, c }
void main() {
switch (ABC.a) {
case ABC.a:
print('a');
case != ABC.a:
print('b or c');
}
}
```
Currently, on `stable` and `master`, I get the following analyzer error:
```console
line 4 • The type 'ABC' is not exhaustively matched by the switch cases since it doesn't match 'ABC.b'.[ (view docs)](https://dart.dev/diagnostics/non_exhaustive_switch_statement)
Try adding a default case or cases that match 'ABC.b'.
```
https://dartpad.dev/?channel=master&id=d02674134c44882884c661d5a4e9b524
Contributor guide
Research direction
Reproduce the enum switch example on stable and master, using the linked DartPad and the reported non_exhaustive_switch_statement diagnostic as the starting points. Check whether `case != ABC.a` is intended to cover the remaining enum values; done means the expected exhaustiveness behavior is decided and the analyzer result is consistent with it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100