Files
sdk/pkg/front_end/testcases/patterns/effect_only.dart
T
Johnni Winther 4efcda0fd2 [cfe] Generate statements for trivial pattern assignments
Closes #52960

Change-Id: I868a7ef5867ad955072ae5425da82c007ca1d73c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/315902
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
2023-07-28 11:11:37 +00:00

36 lines
693 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.
test(List<int> list) {
var (<num>[v] as List<int>) = list;
expect(42, v);
}
test2() {
num? x = 2 > 1 ? 42 : null;
var (v2!) = x;
expect(42, v2);
}
main() {
test(<int>[42]);
throws(() => test(<int>[]));
throws(() => test(<int>[1, 2]));
test2();
}
expect(expected, actual) {
if (expected != actual) throw 'Expected $expected, actual $actual';
}
throws(void Function() f) {
try {
f();
} catch (_) {
return;
}
throw 'Missing exception';
}