dart-sdk/tests/web_2/label_test.dart
Sigmund Cherem 912005267d [web] rename suite dart2js -> web.
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2021-02-04 23:11:32 +00:00

65 lines
1.8 KiB
Dart

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.7
// A break label must be declared where it's used.
undeclaredBreakLabel1() {
foo: { break bar; break foo; } // //# 01: compile-time error
}
undeclaredBreakLabel2() {
foo: while (true) { break bar; break foo; } // //# 02: compile-time error
}
// An unlabeled break must be inside a loop or switch.
noBreakTarget() {
foo: if (true) { break; break foo; } // //# 03: compile-time error
}
// A continue label must be declared where it's used.
undeclaredContinueLabel() {
foo: for (;;) { continue bar; break foo; } // //# 04: compile-time error
}
// An unlabeled continue must be inside a loop.
noContinueTarget() {
foo: if (true) continue; else break foo; // //# 05: compile-time error
}
// A continue label must point to a continue-able statement.
wrongContinueLabel() {
foo: if (true) continue foo; // //# 06: compile-time error
}
// Labels are not captured by closures.
noncaptureLabel() {
foo: { // //# 07: compile-time error
(() { break foo; })(); // //# 07: continued
break foo; // //# 07: continued
} // //# 07: continued
}
// Implicit break targets are not captured by closures.
noncaptureBreak() {
while(true) (() { break; })(); // //# 08: compile-time error
}
// Implicit continue targets are not captured by closures.
noncaptureContinue() {
while(true) (() { continue; })(); // //# 09: compile-time error
}
main() {
undeclaredBreakLabel1();
undeclaredBreakLabel2();
noBreakTarget();
undeclaredContinueLabel();
noContinueTarget();
wrongContinueLabel();
noncaptureLabel();
noncaptureBreak();
noncaptureContinue();
}