Files
sdk/pkg/front_end/testcases/patterns/issue51138.dart
T
Johnni Winther f343c3ceb7 [cfe] Split cached expressions by receiver type
This splits cached expression by receiver type such that the initializing
expression for a cached variable isn't stored in the late variable
initializer, if it can be obtained in different ways. For instance having
both a list pattern and a map pattern in the same switch will trigger
caching of the .length property but obtaining expression differ base on
the receiver type, in the first case List.length and in second case
Map.length.

Closes #51138
Closes #51140

Change-Id: Ic4d8ca394a872113114514f72274413b836fdfb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280081
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-01-30 16:31:50 +00:00

24 lines
514 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.
String test(List list) {
return switch (list) {
<num>[3, >0] => "relational",
[4, var c as num] => "cast",
_ => "default",
};
}
main() {
throws(() => test([4, "42"]));
}
throws(void Function() f) {
try {
f();
} catch (_) {
return;
}
throw 'Missing exception';
}