Files
sdk/pkg/front_end/testcases/patterns/simple_switch.dart
T
Chloe Stefantsova e724a13cd3 [cfe] Implement desugaring for simple switch statements
This CL doesn't cover the following features, among others.

* Guard clauses.
* Multiple patterns per case body.
* Labels.

Part of https://github.com/dart-lang/sdk/issues/49749

Change-Id: I8de86785c44eecbe6e2167dc7a97d9281249af3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276524
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-12-20 10:12:52 +00:00

28 lines
594 B
Dart

// Copyright (c) 2022, 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.
test(dynamic x) {
switch (x) {
case int y:
return y;
case [double z]:
return z;
default:
return null;
}
}
main() {
expectEquals(test(0), 0);
expectEquals(test([3.14]), 3.14);
expectEquals(test("foo"), null);
expectEquals(test(null), null);
}
expectEquals(x, y) {
if (x != y) {
throw "Expected ${x} to be equal to ${y}.";
}
}