5d44b804cd
This changes the lowering of switch expressions and pattern switch statements without continue to only use if-then-else Change-Id: I3bcbb634ec3153a117c4bd6692a276c1c26e648d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279964 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
43 lines
832 B
Dart
43 lines
832 B
Dart
// Copyright (c) 2023, 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.
|
|
|
|
int test(o) {
|
|
switch (o) {
|
|
case [var a]:
|
|
return a;
|
|
case 0:
|
|
continue CASE2;
|
|
CASE1:
|
|
case 1:
|
|
return 1;
|
|
CASE2:
|
|
case 2:
|
|
return 2;
|
|
case 3:
|
|
continue DEFAULT;
|
|
case 4:
|
|
return 4;
|
|
DEFAULT:
|
|
default:
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
main() {
|
|
expect(0, test([0]));
|
|
expect(1, test([1]));
|
|
expect(2, test(0));
|
|
expect(1, test(1));
|
|
expect(2, test(2));
|
|
expect(-1, test(3));
|
|
expect(4, test(4));
|
|
expect(-1, test(5));
|
|
expect(-1, test([]));
|
|
}
|
|
|
|
expect(expected, actual) {
|
|
if (expected != actual) {
|
|
throw 'Expected $expected, actual $actual';
|
|
}
|
|
} |