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:
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:
enum E { e1, e2 }
void f(E x) {
switch (x) {
case E.e1:
print('one');
case E.e2:
print('two');
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.