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');
}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。