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:
dart
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:
dart
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:
dart
void f() {
loop: for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (j != 0) {
break loop;
}
}
}
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。