Files
sdk/pkg/front_end/testcases/patterns/simple_rest_pattern.dart
T
Chloe Stefantsova 1f55c4ce32 [cfe] Add desugaring of non-matching rest pattern
Closes https://github.com/dart-lang/sdk/issues/50797

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

Change-Id: Ide77d1ee262f8778de7eb8743b04508ee290ee10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276940
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2022-12-22 11:25:05 +00:00

51 lines
1022 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.
test1(dynamic x) {
if (x case [int y]) {
return y;
} else {
return null;
}
}
test2(dynamic x) {
if (x case [int y, ...]) {
return y;
} else {
return null;
}
}
test3(dynamic x) {
if (x case [..., int y]) {
return y;
} else {
return null;
}
}
main() {
expectEquals(test1([1]), 1);
expectEquals(test1([1, 2, 3]), null);
expectEquals(test1([]), null);
expectEquals(test1("foo"), null);
expectEquals(test2([1]), 1);
expectEquals(test2([1, 2, 3]), 1);
expectEquals(test2([]), null);
expectEquals(test2("foo"), null);
expectEquals(test3([1]), 1);
expectEquals(test3([1, 2, 3]), 3);
expectEquals(test3([]), null);
expectEquals(test3("foo"), null);
}
expectEquals(x, y) {
if (x != y) {
throw "Expected ${x} to be equal to ${y}.";
}
}