Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit bd39320

Browse files
askeksacommit-bot@chromium.org
authored andcommitted
Recover from error on undefined continue label.
Closes dart-lang/sdk#32800 Change-Id: Idbd11f1c17affc1e9a6dd7f4c6999464bac8982e Reviewed-on: https://dart-review.googlesource.com/50220 Commit-Queue: Aske Simon Christensen <[email protected]> Reviewed-by: Peter von der Ahé <[email protected]>
1 parent 5d89a1a commit bd39320

File tree

6 files changed

+60
-22
lines changed

6 files changed

+60
-22
lines changed

pkg/analyzer/lib/src/fasta/error_converter.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,14 @@ class FastaErrorReporter {
134134
ParserErrorCode.DUPLICATE_LABEL_IN_SWITCH_STATEMENT,
135135
offset,
136136
length,
137-
[arguments['string']]);
137+
[arguments['name']]);
138+
return;
139+
case "LABEL_UNDEFINED":
140+
errorReporter?.reportErrorForOffset(
141+
CompileTimeErrorCode.LABEL_UNDEFINED,
142+
offset,
143+
length,
144+
[arguments['name']]);
138145
return;
139146
case "COVARIANT_MEMBER":
140147
errorReporter?.reportErrorForOffset(

pkg/front_end/lib/src/fasta/fasta_codes_generated.dart

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,32 +1121,28 @@ const MessageCode messageDuplicateDeferred = const MessageCode(
11211121
tip: r"""Try removing all but one 'deferred' keyword.""");
11221122

11231123
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1124-
const Template<
1125-
Message Function(
1126-
String
1127-
string)> templateDuplicateLabelInSwitchStatement = const Template<
1128-
Message Function(String string)>(
1129-
messageTemplate:
1130-
r"""The label '#string' was already used in this switch statement.""",
1131-
tipTemplate: r"""Try choosing a different name for this label.""",
1132-
withArguments: _withArgumentsDuplicateLabelInSwitchStatement);
1124+
const Template<Message Function(String name)>
1125+
templateDuplicateLabelInSwitchStatement =
1126+
const Template<Message Function(String name)>(
1127+
messageTemplate:
1128+
r"""The label '#name' was already used in this switch statement.""",
1129+
tipTemplate: r"""Try choosing a different name for this label.""",
1130+
withArguments: _withArgumentsDuplicateLabelInSwitchStatement);
11331131

11341132
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1135-
const Code<Message Function(String string)>
1136-
codeDuplicateLabelInSwitchStatement =
1137-
const Code<Message Function(String string)>(
1138-
"DuplicateLabelInSwitchStatement",
1133+
const Code<Message Function(String name)> codeDuplicateLabelInSwitchStatement =
1134+
const Code<Message Function(String name)>("DuplicateLabelInSwitchStatement",
11391135
templateDuplicateLabelInSwitchStatement,
11401136
analyzerCode: "DUPLICATE_LABEL_IN_SWITCH_STATEMENT",
11411137
dart2jsCode: "*fatal*");
11421138

11431139
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
1144-
Message _withArgumentsDuplicateLabelInSwitchStatement(String string) {
1140+
Message _withArgumentsDuplicateLabelInSwitchStatement(String name) {
11451141
return new Message(codeDuplicateLabelInSwitchStatement,
11461142
message:
1147-
"""The label '$string' was already used in this switch statement.""",
1143+
"""The label '$name' was already used in this switch statement.""",
11481144
tip: """Try choosing a different name for this label.""",
1149-
arguments: {'string': string});
1145+
arguments: {'name': name});
11501146
}
11511147

11521148
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
@@ -3325,6 +3321,30 @@ const MessageCode messageInvalidVoid = const MessageCode("InvalidVoid",
33253321
tip:
33263322
r"""Try removing 'void' keyword or replace it with 'var', 'final', or a type.""");
33273323

3324+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3325+
const Template<
3326+
Message Function(String name)> templateLabelNotFound = const Template<
3327+
Message Function(String name)>(
3328+
messageTemplate: r"""Can't find label '#name'.""",
3329+
tipTemplate:
3330+
r"""Try defining the label, or correcting the name to match an existing label.""",
3331+
withArguments: _withArgumentsLabelNotFound);
3332+
3333+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3334+
const Code<Message Function(String name)> codeLabelNotFound =
3335+
const Code<Message Function(String name)>(
3336+
"LabelNotFound", templateLabelNotFound,
3337+
analyzerCode: "LABEL_UNDEFINED", dart2jsCode: "*fatal*");
3338+
3339+
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
3340+
Message _withArgumentsLabelNotFound(String name) {
3341+
return new Message(codeLabelNotFound,
3342+
message: """Can't find label '$name'.""",
3343+
tip:
3344+
"""Try defining the label, or correcting the name to match an existing label.""",
3345+
arguments: {'name': name});
3346+
}
3347+
33283348
// DO NOT EDIT. THIS FILE IS GENERATED. SEE TOP OF FILE.
33293349
const Code<Null> codeLibraryDirectiveNotFirst = messageLibraryDirectiveNotFirst;
33303350

pkg/front_end/lib/src/fasta/kernel/body_builder.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,13 @@ class BodyBuilder<Arguments> extends ScopeListener<JumpTarget>
325325
switchScope.unclaimedForwardDeclarations
326326
.forEach((String name, Builder builder) {
327327
if (outerSwitchScope == null) {
328-
deprecated_addCompileTimeError(-1, "Label not found: '$name'.");
328+
JumpTarget target = builder;
329+
for (Statement statement in target.users) {
330+
statement.parent.replaceChild(
331+
statement,
332+
wrapInCompileTimeErrorStatement(statement,
333+
fasta.templateLabelNotFound.withArguments(name)));
334+
}
329335
} else {
330336
outerSwitchScope.forwardDeclareLabel(name, builder);
331337
}

pkg/front_end/messages.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,21 @@ ContinueWithoutLabelInCase:
630630
- "main() { switch (x) {case 1: continue;} }"
631631

632632
DuplicateLabelInSwitchStatement:
633-
template: "The label '#string' was already used in this switch statement."
633+
template: "The label '#name' was already used in this switch statement."
634634
tip: "Try choosing a different name for this label."
635635
analyzerCode: DUPLICATE_LABEL_IN_SWITCH_STATEMENT
636636
dart2jsCode: "*fatal*"
637637
statement:
638638
- "switch (0) {l1: case 0: break; l1: case 1: break;}"
639639

640+
LabelNotFound:
641+
template: "Can't find label '#name'."
642+
tip: "Try defining the label, or correcting the name to match an existing label."
643+
analyzerCode: LABEL_UNDEFINED
644+
dart2jsCode: "*fatal*"
645+
statement:
646+
- "switch (0) {case 0: continue L;}"
647+
640648
InitializedVariableInForEach:
641649
template: "The loop variable in a for-each loop can't be initialized."
642650
tip: "Try removing the initializer, or using a different kind of loop."

tests/language/language_kernel.status

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ private_member1_negative_test: Fail
188188
private_member2_negative_test: Fail
189189
private_member3_negative_test: Fail
190190
static_call_wrong_argument_count_negative_test: Fail
191-
switch4_negative_test: Crash
192191
type_variable_static_context_negative_test: Fail
193192
unresolved_in_factory_negative_test: Fail
194193
unresolved_top_level_method_negative_test: Fail

tests/language_2/language_2_kernel.status

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,6 @@ super_operator_index5_test: CompileTimeError
13281328
super_operator_index6_test: CompileTimeError
13291329
super_operator_index7_test: CompileTimeError
13301330
super_operator_index8_test: CompileTimeError
1331-
switch4_negative_test: Crash
13321331
try_catch_test/01: MissingCompileTimeError
13331332
type_promotion_functions_test/02: CompileTimeError
13341333
type_promotion_functions_test/03: CompileTimeError
@@ -2060,7 +2059,6 @@ super_operator_index_test/04: MissingCompileTimeError
20602059
super_operator_index_test/05: MissingCompileTimeError
20612060
super_operator_index_test/06: MissingCompileTimeError
20622061
super_operator_index_test/07: MissingCompileTimeError
2063-
switch4_negative_test: Crash
20642062
switch_fallthru_test/01: MissingCompileTimeError
20652063
symbol_literal_test/01: MissingCompileTimeError
20662064
sync_generator1_test/01: MissingCompileTimeError

0 commit comments

Comments
 (0)