break_label_on_switch_member
A break label resolves to the 'case' or 'default' statement.
Description
#The analyzer produces this diagnostic when a break in a case clause inside a switch statement has a label that is associated with another case clause.
Example
#The following code produces this diagnostic because the label l
is
associated with the case clause for 0
:
dart
void f(int i) {
switch (i) {
l: case 0:
break;
case 1:
break l;
}
}
Common fixes
#If the intent is to transfer control to the statement after the switch, then remove the label from the break statement:
dart
void f(int i) {
switch (i) {
case 0:
break;
case 1:
break;
}
}
If the intent is to transfer control to a different case block, then use
continue
rather than break
:
dart
void f(int i) {
switch (i) {
l: case 0:
break;
case 1:
continue l;
}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。