mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 06:20:13 +00:00
912005267d
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>
62 lines
1.8 KiB
Dart
62 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.
|
|
|
|
// 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();
|
|
}
|