Files
sdk/pkg/front_end/testcases/patterns/simple_pattern_variable_declaration.dart
T
Chloe Stefantsova f1ce203361 [cfe] Add desugaring of simple cases of pattern variable declaration
The late variables aren't supported in this CL.

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

Change-Id: Iebc50f716e3575c6dd7bce915e5e294d4c8c8363
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276525
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2022-12-23 09:30:39 +00:00

41 lines
911 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) {
var [int y] = x;
return y;
}
test2(dynamic x) {
var [String a, ..., String b] = x;
return a + b;
}
main() {
expectEquals(test1([0]), 0);
expectThrows(() => test1([]));
expectThrows(() => test1([0, 1, 2]));
expectEquals(test2(["one", "two", "three", "four"]), "onefour");
expectThrows(() => test2(["one"]));
expectThrows(() => test2("one"));
expectThrows(() => test2(null));
}
expectEquals(x, y) {
if (x != y) {
throw "Expected ${x} to be equal to ${y}.";
}
}
expectThrows(void Function() f) {
bool hasThrown = true;
try {
f();
hasThrown = false;
} catch(e) {}
if (!hasThrown) {
throw "Expected function to throw.";
}
}