label_undefined
Can't reference an undefined label '{0}'.
Description
#The analyzer produces this diagnostic when it finds a reference to a label that isn't defined in the scope of the break
or continue
statement that is referencing it.
Example
#The following code produces this diagnostic because the label loop
isn't defined anywhere:
void f() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break loop;
}
}
}
}
Common fixes
#If the label should be on the innermost enclosing do
, for
, switch
, or while
statement, then remove the label:
void f() {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break;
}
}
}
}
If the label should be on some other statement, then add the label:
void f() {
loop: for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break loop;
}
}
}
}
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.