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
:
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:
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
:
void f(int i) {
switch (i) {
l: case 0:
break;
case 1:
continue l;
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.7.3. Page last updated on 2025-05-08. View source or report an issue.