unreachable_ switch_ default
Details about the 'unreachable_switch_default' diagnostic produced by the Dart analyzer.
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');
}
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.