| library /*isNonNullableByDefault*/; |
| import self as self; |
| import "dart:core" as core; |
| |
| static method test1(dynamic x) → dynamic { |
| for (final dynamic #t1 in x as{TypeError,ForDynamic,ForNonNullableByDefault} core::Iterable<dynamic>) { |
| core::int y; |
| { |
| final synthesized dynamic #0#0 = #t1; |
| late final synthesized dynamic #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}; |
| if(!(#0#0 is{ForNonNullableByDefault} core::List<dynamic> && #0#0{core::List<dynamic>}.{core::List::length}{core::int} =={core::num::==}{(core::Object) → core::bool} #C1 && (#0#6 is{ForNonNullableByDefault} core::int && (let final dynamic #t2 = y = #0#6{core::int} in true)))) |
| throw new core::StateError::•("Pattern matching error"); |
| } |
| if(y.{core::num::%}(10){(core::num) → core::int} =={core::num::==}{(core::Object) → core::bool} 0) { |
| return y; |
| } |
| } |
| return 1.{core::int::unary-}(){() → core::int}; |
| } |
| static method test2(core::Iterable<core::List<core::String>> x) → dynamic { |
| for (final core::List<core::String> #t3 in x) { |
| core::String y; |
| { |
| final synthesized dynamic #0#0 = #t3; |
| late final synthesized core::int #0#1 = #0#0{core::List<core::String>}.{core::List::length}{core::int}; |
| late final synthesized core::String #0#4 = #0#0{core::List<core::String>}.{core::List::[]}(#0#1.{core::num::-}(1){(core::num) → core::int}){(core::int) → core::String}; |
| if(!(#0#1.{core::num::>=}(#C1){(core::num) → core::bool} && (#0#4 is{ForNonNullableByDefault} core::String && (let final dynamic #t4 = y = #0#4 in true)))) |
| throw new core::StateError::•("Pattern matching error"); |
| } |
| if(y.{core::String::startsWith}("f"){(core::Pattern, [core::int]) → core::bool}) { |
| return y; |
| } |
| } |
| return ""; |
| } |
| static method test3(core::Iterable<dynamic> x) → dynamic { |
| for (final dynamic #t5 in x) { |
| core::int y; |
| { |
| final synthesized dynamic #0#0 = #t5; |
| late final synthesized dynamic #0#6 = #0#0{core::List<dynamic>}.{core::List::[]}(0){(core::int) → dynamic}; |
| if(!(#0#0 is{ForNonNullableByDefault} core::List<dynamic> && #0#0{core::List<dynamic>}.{core::List::length}{core::int}.{core::num::>=}(#C1){(core::num) → core::bool} && (#0#6 is{ForNonNullableByDefault} core::int && (let final dynamic #t6 = y = #0#6{core::int} in true)))) |
| throw new core::StateError::•("Pattern matching error"); |
| } |
| return y; |
| } |
| return 1.{core::int::unary-}(){() → core::int}; |
| } |
| static method main() → dynamic { |
| self::expectEquals(self::test1(<core::List<core::int>>[<core::int>[1], <core::int>[2], <core::int>[3]]), 1.{core::int::unary-}(){() → core::int}); |
| self::expectEquals(self::test1(<core::List<core::int>>[<core::int>[1], <core::int>[2], <core::int>[30]]), 30); |
| self::expectEquals(self::test2(<core::List<core::String>>[<core::String>["foo", "bar", "baz"], <core::String>["bar", "foo", "baz"], <core::String>["bar", "baz", "foo"]]), "foo"); |
| self::expectEquals(self::test2(<core::List<core::String>>[]), ""); |
| self::expectThrows(() → void => self::test3(<dynamic>[<core::int?>[null, 1, 2]])); |
| self::expectEquals(self::test3(<dynamic>[]), 1.{core::int::unary-}(){() → core::int}); |
| } |
| 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 function to throw."; |
| } |
| } |
| |
| constants { |
| #C1 = 1 |
| } |