blob: f1fa627ad0b30006e533d775778e68d9725e6594 [file] [log] [blame]
library;
import self as self;
import "dart:core" as core;
static method test1(dynamic x) dynamic {
core::int a;
{
final synthesized dynamic #0#0 = x as{TypeError,ForDynamic} core::List<core::int>;
if(!(#0#0 is core::List<dynamic> && #0#0{core::List<dynamic>}.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} #C1 && (let final core::int #t1 = a = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic} as core::int in true)))
throw{for-error-handling} new core::StateError::•("Pattern matching error");
}
return a;
}
static method test2(dynamic x) dynamic {
core::int a;
core::int b;
core::int c;
{
final synthesized dynamic #1#0 = ( block {
final synthesized dynamic #0#0 = x as{TypeError,ForDynamic} core::List<core::int>;
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::>=}(#C1){(core::num) → core::bool} && ((let final core::int #t2 = a = (#0#6#isSet ?{dynamic} #0#6{dynamic} : let final core::bool* #t3 = #0#6#isSet = true in #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}) as core::int in true) && (let final core::int #t4 = b = (#0#6#isSet ?{dynamic} #0#6{dynamic} : let final core::bool* #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))))
throw{for-error-handling} new core::StateError::•("Pattern matching error");
} =>#0#0) as{TypeError,ForDynamic} core::List<core::int>;
if(!(#1#0 is core::List<dynamic> && #1#0{core::List<dynamic>}.{core::List::length}{core::int}.{core::num::>=}(#C1){(core::num) → core::bool} && (let final core::int #t6 = c = #1#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic} as core::int in true)))
throw{for-error-handling} new core::StateError::•("Pattern matching error");
}
return a.{core::num::+}(b){(core::num) core::int}.{core::num::+}(c){(core::num) core::int};
}
static method main() dynamic {
self::expectEquals(self::test1(core::_GrowableList::_literal1<core::int>(1)), 1);
self::expectThrows(() void => self::test1(core::_GrowableList::•<dynamic>(0)));
self::expectThrows(() void => self::test1(core::_GrowableList::_literal3<core::int>(1, 2, 3)));
self::expectThrows(() void => self::test1("foo"));
self::expectThrows(() void => self::test1(null));
self::expectEquals(self::test2(core::_GrowableList::_literal1<core::int>(1)), 3);
self::expectThrows(() void => self::test2(1));
}
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}.";
}
}
static method expectThrows(() void f) dynamic {
core::bool hasThrown = true;
try {
f(){() void};
hasThrown = false;
}
on core::Object catch(final core::Object e) {
}
if(!hasThrown) {
throw "Expected the function to throw.";
}
}
constants {
#C1 = 1
}