Files
sdk/pkg/front_end/testcases/patterns/local_shadows_pattern.dart.weak.expect
T
Johnni Winther c6347389d2 [cfe] Move irrefutable tails into the case body
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>
2023-12-07 11:13:30 +00:00

111 lines
3.7 KiB
Plaintext

library;
import self as self;
import "dart:core" as core;
static method test1(dynamic x) → dynamic {
#L1:
{
final synthesized dynamic #0#0 = x;
{
hoisted core::int x;
if(#0#0 is core::int && (let final dynamic #t1 = x = #0#0{core::int} in true)) {
{
{
core::String x = "foo";
return x;
}
}
}
}
{
{
{
return "bar";
}
}
}
}
}
static method test2(dynamic x) → dynamic {
#L2:
{
final synthesized dynamic #0#0 = x;
synthesized core::bool #0#4;
synthesized core::bool #0#4#isSet = false;
synthesized dynamic #0#6;
synthesized core::bool #0#6#isSet = false;
synthesized dynamic #0#7;
synthesized core::bool #0#7#isSet = false;
{
lowered hoisted core::int x#case#0;
lowered hoisted core::int x#case#1;
if(#0#0 is core::List<dynamic> && (#0#4#isSet ?{core::bool} #0#4{core::bool} : let final dynamic #t2 = #0#4#isSet = true in #0#4 = #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 #t3 = #0#6#isSet = true in #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}) is core::int && (let final dynamic #t4 = x#case#0 = (#0#6#isSet ?{dynamic} #0#6{dynamic} : let final dynamic #t5 = #0#6#isSet = true in #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}) as{Unchecked} core::int in true)) || #0#0 is core::List<dynamic> && (#0#4#isSet ?{core::bool} #0#4{core::bool} : let final dynamic #t6 = #0#4#isSet = true in #0#4 = #0#0{core::List<dynamic>}.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} #C1) && ((#0#7#isSet ?{dynamic} #0#7{dynamic} : let final dynamic #t7 = #0#7#isSet = true in #0#7 = #0#0{core::List<dynamic>}.{core::List::[]}(1){(core::int) → dynamic}) is core::int && (let final dynamic #t8 = x#case#1 = (#0#7#isSet ?{dynamic} #0#7{dynamic} : let final dynamic #t9 = #0#7#isSet = true in #0#7 = #0#0{core::List<dynamic>}.{core::List::[]}(1){(core::int) → dynamic}) as{Unchecked} core::int in true))) {
{
core::String x = "foo";
return x;
}
}
}
{
{
{
return "bar";
}
}
}
}
}
static method test3(dynamic x) → dynamic {
{
hoisted core::int x;
final synthesized dynamic #0#0 = x;
if(#0#0 is core::int) {
x = #0#0{core::int};
{
core::String x = "foo";
return x;
}
}
else {
return "bar";
}
}
}
static method test4(dynamic x) → dynamic {
core::Function f = () → core::int => 0;
{
hoisted core::int x;
final synthesized dynamic #0#0 = x;
if(#0#0 is core::int) {
x = #0#0{core::int};
{
core::String x = (() → core::String {
f = () → core::int => 1;
return "foo";
})(){() → core::String};
}
}
}
return f();
}
static method main() → dynamic {
self::expectEquals(self::test1(0), "foo");
self::expectEquals(self::test1("foo"), "bar");
self::expectEquals(self::test2(<core::Object>[0, false]), "foo");
self::expectEquals(self::test2(<core::Object>[false, 0]), "foo");
self::expectEquals(self::test2("foo"), "bar");
self::expectEquals(self::test3(0), "foo");
self::expectEquals(self::test3("foo"), "bar");
self::expectEquals(self::test4(0), 1);
self::expectEquals(self::test4("foo"), 0);
}
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 = 2
}