unreachable_switch_default
This default clause is covered by the previous cases.
Description
#The analyzer produces this diagnostic when a default
clause in a switch
statement doesn't match anything because all of the matchable values are matched by an earlier case
clause.
Example
#The following code produces this diagnostic because the values E.e1
and E.e2
were matched in the preceding cases:
dart
enum E { e1, e2 }
void f(E x) {
switch (x) {
case E.e1:
print('one');
case E.e2:
print('two');
default:
print('other');
}
}
Common fixes
#Remove the unnecessary default
clause:
dart
enum E { e1, e2 }
void f(E x) {
switch (x) {
case E.e1:
print('one');
case E.e2:
print('two');
}
}
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-05-08. View source or report an issue.