dart-lang / dart-lang/language

Switch expression is not exhaustive on integers

Open
#3,083 11 comments 40 reactions 0 assignees View on GitHub
patterns
Dominant language
TeX
Stars
2.9k
Forks
239
Avg merge
2d 18h
Merged PRs (30d)
14

Description

* Dart 3.0.0

The analyzer claims that the following code snippet isn't exhaustive when it is. It emits the following message: `The type 'int' is not exhaustively matched by the switch cases since it doesn't match 'int()'`.

```dart
void main() {
final foo = switch ('a'.compareTo('b')) {
> 0 => 'more',
== 0 => 'equal',
< 0 => 'less',
};
}
```

Contributor guide

Open the contributing guide

Research direction

No implementation file or test is named. Start by reproducing the Dart 3.0.0 switch expression from the issue and trace the analyzer's exhaustiveness check for relational patterns on int; done means the exhaustive cases no longer produce the reported int() diagnostic.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.