c6347389d2
This moves pattern variable assignments of fully matched expressions into the case body. This will help backends (dart2js in particular) to reason about the code flow. Closes #54115 Change-Id: I598a384a829f16e91ab2d6a309499cf20b9cc121 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339122 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Jens Johansen <jensj@google.com>
40 lines
1.5 KiB
Plaintext
40 lines
1.5 KiB
Plaintext
library;
|
|
import self as self;
|
|
import "dart:core" as core;
|
|
|
|
static method test(dynamic x) → dynamic {
|
|
{
|
|
hoisted core::String y;
|
|
final synthesized dynamic #0#0 = x;
|
|
synthesized dynamic #0#6;
|
|
synthesized core::bool #0#6#isSet = false;
|
|
if(#0#0 is core::List<dynamic> && #0#0{core::List<dynamic>}.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} #C1 && (#0#6#isSet ?{dynamic} #0#6{dynamic} : let final dynamic #t1 = #0#6#isSet = true in #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}) is core::String) {
|
|
y = (#0#6#isSet ?{dynamic} #0#6{dynamic} : let final dynamic #t2 = #0#6#isSet = true in #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}) as{Unchecked} core::String;
|
|
{
|
|
return y;
|
|
}
|
|
}
|
|
else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
static method main() → dynamic {
|
|
self::expectEquals(self::test(<core::String>["one", "two", "three"]), null);
|
|
self::expectEquals(self::test(<core::String>["one"]), "one");
|
|
self::expectEquals(self::test(<core::int>[1, 2, 3]), null);
|
|
self::expectEquals(self::test(<core::int>[1]), null);
|
|
self::expectEquals(self::test(<core::bool>[true, false]), null);
|
|
self::expectEquals(self::test(<core::bool>[true]), null);
|
|
self::expectEquals(self::test(<dynamic>[]), null);
|
|
}
|
|
static method expectEquals(dynamic x, dynamic y) → dynamic {
|
|
if(!(x =={core::Object::==}{(core::Object) → core::bool} y)) {
|
|
throw "Expected ${x} to be equal to ${y}.";
|
|
}
|
|
}
|
|
|
|
constants {
|
|
#C1 = 1
|
|
}
|