| library /*isLegacy*/; |
| import self as self; |
| import "exhaustiveness_lib.dart" as exh; |
| import "dart:core" as core; |
| |
| import "org-dartlang-testcase:///exhaustiveness_lib.dart"; |
| |
| static method main() → dynamic { |
| self::expect(true, exh::boolSwitchStatement(true)); |
| self::expect(false, exh::boolSwitchStatement(false)); |
| self::throws(() → core::bool* => exh::boolSwitchStatement(null)); |
| self::expect(true, exh::boolSwitchExpression(true)); |
| self::expect(false, exh::boolSwitchExpression(false)); |
| self::throws(() → core::bool* => exh::boolSwitchExpression(null)); |
| self::expect(0, exh::sealedSwitchStatement(new exh::A1::•())); |
| self::expect(1, exh::sealedSwitchStatement(new exh::A2::•())); |
| self::throws(() → core::int* => exh::sealedSwitchStatement(null)); |
| self::expect(0, exh::sealedSwitchExpression(new exh::A1::•())); |
| self::expect(1, exh::sealedSwitchExpression(new exh::A2::•())); |
| self::throws(() → core::int* => exh::sealedSwitchExpression(null)); |
| } |
| static method expect(dynamic expected, dynamic actual) → dynamic { |
| if(!(expected =={core::Object::==}{(core::Object*) →* core::bool*} actual)) |
| throw "Expected ${expected}, actual ${actual}"; |
| } |
| static method throws(() →* void f) → dynamic { |
| try { |
| f(){() →* void}; |
| } |
| on dynamic catch(final dynamic e) { |
| core::print(e); |
| return; |
| } |
| throw "Missing throws"; |
| } |
| |
| library; |
| import self as exh; |
| import "dart:core" as core; |
| import "dart:_internal" as _in; |
| |
| abstract sealed class A extends core::Object { |
| synthetic constructor •() → exh::A |
| : super core::Object::•() |
| ; |
| } |
| class A1 extends exh::A { |
| synthetic constructor •() → exh::A1 |
| : super exh::A::•() |
| ; |
| } |
| class A2 extends exh::A { |
| synthetic constructor •() → exh::A2 |
| : super exh::A::•() |
| ; |
| } |
| static method boolSwitchStatement(core::bool b) → core::bool { |
| #L1: |
| switch(b) /* isExplicitlyExhaustive, core::bool */ { |
| #L2: |
| case #C1: |
| { |
| return true; |
| } |
| #L3: |
| case #C2: |
| { |
| return false; |
| } |
| #L4: |
| default: |
| throw new _in::ReachabilityError::•("`null` encountered as case in a switch statement with a non-nullable type."); |
| } |
| } |
| static method boolSwitchExpression(core::bool b) → core::bool |
| return block { |
| core::bool #t1; |
| #L5: |
| switch(b) /* isExplicitlyExhaustive, core::bool */ { |
| #L6: |
| case #C1: |
| { |
| #t1 = true; |
| break #L5; |
| } |
| #L7: |
| case #C2: |
| { |
| #t1 = false; |
| break #L5; |
| } |
| #L8: |
| default: |
| throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable type."); |
| } |
| } =>#t1; |
| static method sealedSwitchStatement(exh::A a) → core::int { |
| #L9: |
| { |
| final synthesized exh::A #0#0 = a; |
| { |
| if(#0#0 is exh::A1) { |
| { |
| return 0; |
| } |
| } |
| } |
| { |
| if(#0#0 is exh::A2) { |
| { |
| return 1; |
| } |
| } |
| } |
| throw new _in::ReachabilityError::•("`null` encountered as case in a switch statement with a non-nullable type."); |
| } |
| } |
| static method sealedSwitchExpression(exh::A a) → core::int |
| return block { |
| core::int #t2; |
| final synthesized exh::A #0#0 = a; |
| #L10: |
| { |
| { |
| if(#0#0 is exh::A1) { |
| #t2 = 0; |
| break #L10; |
| } |
| } |
| { |
| if(#0#0 is exh::A2) { |
| #t2 = 1; |
| break #L10; |
| } |
| } |
| throw new _in::ReachabilityError::•("`null` encountered as case in a switch expression with a non-nullable type."); |
| } |
| } =>#t2; |
| |
| constants { |
| #C1 = true |
| #C2 = false |
| } |