//! > match multi numbers.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: felt252) -> felt252 {
    let b = match a {
        5 => { 550 },
        6 => { 70 },
        _ => { 90 }
    };
    return b;
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unsupported match - numbers must be sequential starting from 0.
 --> lib.cairo:2:13
    let b = match a {
            ^*******^

//! > lowering_flat
Parameters: v0: core::felt252

//! > ==========================================================================

//! > match felt.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: felt252) -> felt252 {
    match a {
        0 => 11,
        2 => 33,
        1 => 22,
        _ => 44,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v1) => blk2,
  })

blk1:
Statements:
  (v2: core::felt252) <- 11
End:
  Return(v2)

blk2:
Statements:
  (v3: core::felt252) <- 2
  (v4: core::felt252) <- core::felt252_sub(v0, v3)
End:
  Match(match core::felt252_is_zero(v4) {
    IsZeroResult::Zero => blk3,
    IsZeroResult::NonZero(v5) => blk4,
  })

blk3:
Statements:
  (v6: core::felt252) <- 33
End:
  Return(v6)

blk4:
Statements:
  (v7: core::felt252) <- 1
  (v8: core::felt252) <- core::felt252_sub(v0, v7)
End:
  Match(match core::felt252_is_zero(v8) {
    IsZeroResult::Zero => blk5,
    IsZeroResult::NonZero(v9) => blk6,
  })

blk5:
Statements:
  (v10: core::felt252) <- 22
End:
  Return(v10)

blk6:
Statements:
  (v11: core::felt252) <- 44
End:
  Return(v11)

//! > ==========================================================================

//! > Test match 0.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: felt252, x: felt252) -> felt252 {
    match x {
        0 => a + 1,
        _ => x,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252, v1: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v1) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v2) => blk2,
  })

blk1:
Statements:
  (v3: core::felt252) <- 1
  (v4: core::felt252) <- core::felt252_add(v0, v3)
End:
  Return(v4)

blk2:
Statements:
End:
  Return(v1)

//! > ==========================================================================

//! > Test array at.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: @Array::<felt252>) -> Option<Box<@felt252>> {
    core::array::array_get(a, 0_u32)
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::RangeCheck, v1: @core::array::Array::<core::felt252>
blk0 (root):
Statements:
  (v2: core::integer::u32) <- 0
End:
  Match(match core::array::array_get::<core::felt252>(v0, v1, v2) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5) => blk2,
  })

blk1:
Statements:
  (v6: core::option::Option::<core::box::Box::<@core::felt252>>) <- Option::Some(v4)
End:
  Return(v3, v6)

blk2:
Statements:
  (v7: ()) <- struct_construct()
  (v8: core::option::Option::<core::box::Box::<@core::felt252>>) <- Option::None(v7)
End:
  Return(v5, v8)

//! > ==========================================================================

//! > Test match zero with non-zero value.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    let x = 7;
    match x {
        12 => x,
        _ => 7,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unsupported match - numbers must be sequential starting from 0.
 --> lib.cairo:3:5
    match x {
    ^*******^

//! > lowering_flat
Parameters:

//! > ==========================================================================

//! > Test unsupported match zero.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    let x = 7;
    match x {
        0 => x,
        1 => 7,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Match is non exhaustive - match over a numerical value must have a wildcard card pattern (`_`).
 --> lib.cairo:3:5
    match x {
    ^*******^

//! > lowering_flat
Parameters:

//! > ==========================================================================

//! > Test supported match non felt252 value.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
    match 5 {
        0_u8 => 7,
        1_u8 | 2_u8 => 8,
        _ => 9,
    };
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u8) <- 5
  (v1: core::felt252) <- core::integer::u8_to_felt252(v0)
End:
  Match(match core::felt252_is_zero(v1) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v2) => blk2,
  })

blk1:
Statements:
End:
  Return()

blk2:
Statements:
  (v3: core::felt252) <- 1
  (v4: core::felt252) <- core::felt252_sub(v1, v3)
End:
  Match(match core::felt252_is_zero(v4) {
    IsZeroResult::Zero => blk3,
    IsZeroResult::NonZero(v5) => blk4,
  })

blk3:
Statements:
End:
  Goto(blk6, {})

blk4:
Statements:
  (v6: core::felt252) <- 2
  (v7: core::felt252) <- core::felt252_sub(v1, v6)
End:
  Match(match core::felt252_is_zero(v7) {
    IsZeroResult::Zero => blk5,
    IsZeroResult::NonZero(v8) => blk7,
  })

blk5:
Statements:
End:
  Goto(blk6, {})

blk6:
Statements:
End:
  Return()

blk7:
Statements:
End:
  Return()

//! > ==========================================================================

//! > Test unsupported match non felt252 value.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
    match 5 {
        0_u8 => 7,
        1_felt252 | 2_u8 => 8,
        _ => 9,
    };
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics
error: Type mismatch: `core::felt252` and `core::integer::u8`.
 --> lib.cairo:4:9
        1_felt252 | 2_u8 => 8,
        ^*******^

//! > lowering_diagnostics

//! > lowering_flat
<Failed lowering function - run with RUST_LOG=warn (or less) to see diagnostics>

//! > ==========================================================================

//! > Test empty enum match.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
    match Option::Some(5) {};
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Missing match arm: `Some` not covered.
 --> lib.cairo:2:5
    match Option::Some(5) {};
    ^**********************^

error: Missing match arm: `None` not covered.
 --> lib.cairo:2:5
    match Option::Some(5) {};
    ^**********************^

//! > lowering_flat
Parameters:

//! > ==========================================================================

//! > Test empty enum match on empty enum.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(e: EmptyEnum) {
    match e {};
}

//! > function_name
foo

//! > module_code
enum EmptyEnum {}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: test::EmptyEnum
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
  })

//! > ==========================================================================

//! > Test empty extern match.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() {
    match felt252_is_zero(5) {};
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Missing match arm: `Zero` not covered.
 --> lib.cairo:2:11
    match felt252_is_zero(5) {};
          ^****************^

error: Missing match arm: `NonZero` not covered.
 --> lib.cairo:2:11
    match felt252_is_zero(5) {};
          ^****************^

//! > lowering_flat
Parameters:

//! > ==========================================================================

//! > Test otherwise extern match arm.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    match get_a() {
        A::One(_) => 2,
        _ => 3,
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: (),
    Two: (),
    Three: (),
}

extern fn get_a() -> A nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
End:
  Match(match test::get_a() {
    A::One => blk1,
    A::Two => blk2,
    A::Three => blk3,
  })

blk1:
Statements:
  (v0: core::felt252) <- 2
End:
  Return(v0)

blk2:
Statements:
End:
  Goto(blk4, {})

blk3:
Statements:
End:
  Goto(blk4, {})

blk4:
Statements:
  (v1: core::felt252) <- 3
End:
  Return(v1)

//! > ==========================================================================

//! > Test otherwise match arm.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A) -> felt252 {
    match a {
        A::Two(_) => 2,
        A::One(_) => 1,
        _ => 3,
        A::Two(_) => 4,
        A::Three(_) => 5,
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: (),
    Two: (),
    Three: (felt252, felt252),
    Four: (felt252,),
}

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unreachable pattern arm.
 --> lib.cairo:12:9
        A::Two(_) => 4,
        ^*******^

error: Unreachable pattern arm.
 --> lib.cairo:13:9
        A::Three(_) => 5,
        ^*********^

//! > lowering_flat
Parameters: v0: test::A
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
    A::One(v1) => blk1,
    A::Two(v2) => blk2,
    A::Three(v3) => blk3,
    A::Four(v4) => blk4,
  })

blk1:
Statements:
  (v5: core::felt252) <- 1
End:
  Return(v5)

blk2:
Statements:
  (v6: core::felt252) <- 2
End:
  Return(v6)

blk3:
Statements:
End:
  Goto(blk5, {})

blk4:
Statements:
End:
  Goto(blk5, {})

blk5:
Statements:
  (v7: core::felt252) <- 3
End:
  Return(v7)

//! > ==========================================================================

//! > Test out of order extern match arm.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    match get_a() {
        A::Two(_) => { 2 },
        A::One(_) => { 1 },
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: (),
    Two: (),
}

extern fn get_a() -> A nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:
blk0 (root):
Statements:
End:
  Match(match test::get_a() {
    A::One => blk1,
    A::Two => blk2,
  })

blk1:
Statements:
  (v0: core::felt252) <- 1
End:
  Return(v0)

blk2:
Statements:
  (v1: core::felt252) <- 2
End:
  Return(v1)

//! > ==========================================================================

//! > Test out of order match arm.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A) -> felt252 {
    match a {
        A::Two(_) => { 2 },
        A::One(_) => { 1 },
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: (),
    Two: (),
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: test::A
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
    A::One(v1) => blk1,
    A::Two(v2) => blk2,
  })

blk1:
Statements:
  (v3: core::felt252) <- 1
End:
  Return(v3)

blk2:
Statements:
  (v4: core::felt252) <- 2
End:
  Return(v4)

//! > ==========================================================================

//! > Match on tuples.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: (felt252, felt252)) -> felt252 {
    match a {
        (0, 1) => 0,
        _ => 1,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unsupported matched value. Currently, match on tuples only supports enums as tuple members.
 --> lib.cairo:2:11
    match a {
          ^

//! > lowering_flat
Parameters: v0: (core::felt252, core::felt252)

//! > ==========================================================================

//! > Match with complex patterns.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: Option<Option<felt252>>) -> felt252 {
    match a {
        Option::Some(Option::Some(x)) => x,
        Option::None(_) => 1,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Inner patterns are not in this context.
 --> lib.cairo:3:22
        Option::Some(Option::Some(x)) => x,
                     ^*************^

//! > lowering_flat
Parameters: v0: core::option::Option::<core::option::Option::<core::felt252>>

//! > ==========================================================================

//! > Test missing arms.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A) -> felt252 {
    match a {
        A::Two(_) => 2,
        A::One(_) => 1,
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: (),
    Two: (),
    Three: (),
    Four: (),
}

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Missing match arm: `Three` not covered.
 --> lib.cairo:8:5
    match a {
    ^*******^

error: Missing match arm: `Four` not covered.
 --> lib.cairo:8:5
    match a {
    ^*******^

//! > lowering_flat
Parameters: v0: test::A

//! > ==========================================================================

//! > Test match on bool literals.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: bool) -> felt252 {
    match a {
        true => 2,
        false => 1,
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::bool
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
    bool::False(v1) => blk1,
    bool::True(v2) => blk2,
  })

blk1:
Statements:
  (v3: core::felt252) <- 1
End:
  Return(v3)

blk2:
Statements:
  (v4: core::felt252) <- 2
End:
  Return(v4)

//! > ==========================================================================

//! > Test match with or pattern with arm variables.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: MyEnum) -> felt252 {
    match a {
        MyEnum::A(x) | MyEnum::B((x, _)) => x,
        MyEnum::C((x, _, t)) | MyEnum::D(P { x, z: t, .. }) => x + t,
    }
}

//! > function_name
foo

//! > module_code
struct P {
    x: felt252,
    y: felt252,
    z: felt252,
    w: felt252,
}
enum MyEnum {
    A: felt252,
    C: (felt252, felt252, felt252),
    B: (felt252, felt252),
    D: P,
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: test::MyEnum
blk0 (root):
Statements:
End:
  Match(match_enum(v0) {
    MyEnum::A(v1) => blk1,
    MyEnum::C(v2) => blk2,
    MyEnum::B(v3) => blk3,
    MyEnum::D(v4) => blk4,
  })

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
  (v5: core::felt252, v6: core::felt252, v7: core::felt252) <- struct_destructure(v2)
End:
  Goto(blk5, {v5 -> v8, v7 -> v9})

blk3:
Statements:
  (v10: core::felt252, v11: core::felt252) <- struct_destructure(v3)
End:
  Return(v10)

blk4:
Statements:
  (v12: core::felt252, v13: core::felt252, v14: core::felt252, v15: core::felt252) <- struct_destructure(v4)
End:
  Goto(blk5, {v12 -> v8, v14 -> v9})

blk5:
Statements:
  (v16: core::felt252) <- core::felt252_add(v8, v9)
End:
  Return(v16)

//! > ==========================================================================

//! > Test match with or pattern on felt252

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: felt252) -> felt252 {
    match a {
        0 | 1 => 11,
        2 | 3 => 12,
        4 | _ => 13,
    }
}

//! > function_name
foo

//! > module_code
struct P {
    x: felt252,
    y: felt252,
    z: felt252,
    w: felt252,
}
enum MyEnum {
    A: felt252,
    B: (felt252, felt252),
    C: (felt252, felt252, felt252),
    D: P,
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk1,
    IsZeroResult::NonZero(v1) => blk2,
  })

blk1:
Statements:
End:
  Goto(blk4, {})

blk2:
Statements:
  (v2: core::felt252) <- 1
  (v3: core::felt252) <- core::felt252_sub(v0, v2)
End:
  Match(match core::felt252_is_zero(v3) {
    IsZeroResult::Zero => blk3,
    IsZeroResult::NonZero(v4) => blk5,
  })

blk3:
Statements:
End:
  Goto(blk4, {})

blk4:
Statements:
  (v5: core::felt252) <- 11
End:
  Return(v5)

blk5:
Statements:
  (v6: core::felt252) <- 2
  (v7: core::felt252) <- core::felt252_sub(v0, v6)
End:
  Match(match core::felt252_is_zero(v7) {
    IsZeroResult::Zero => blk6,
    IsZeroResult::NonZero(v8) => blk7,
  })

blk6:
Statements:
End:
  Goto(blk9, {})

blk7:
Statements:
  (v9: core::felt252) <- 3
  (v10: core::felt252) <- core::felt252_sub(v0, v9)
End:
  Match(match core::felt252_is_zero(v10) {
    IsZeroResult::Zero => blk8,
    IsZeroResult::NonZero(v11) => blk10,
  })

blk8:
Statements:
End:
  Goto(blk9, {})

blk9:
Statements:
  (v12: core::felt252) <- 12
End:
  Return(v12)

blk10:
Statements:
  (v13: core::felt252) <- 13
End:
  Return(v13)

//! > ==========================================================================

//! > Test match on enum tuples.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A, b: A) -> felt252 {
    let x = (@a, b);
    let y = @x;
    match y {
        (A::Two((t, _)), A::One) => **t + 3,
        (A::Two, _) => 2,
        (A::One(_), A::One(_)) => 1,
        (_, A::Three(_)) => 3,
        (_, _) => 6,
    }
}

//! > function_name
foo

//! > module_code
#[derive(Copy, Drop)]
enum A {
    One: felt252,
    Two: (felt252, felt252),
    Three: (),
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: test::A, v1: test::A
blk0 (root):
Statements:
  (v2: test::A, v3: @test::A) <- snapshot(v0)
  (v4: (@test::A, test::A)) <- struct_construct(v3, v1)
  (v5: (@test::A, test::A), v6: @(@test::A, test::A)) <- snapshot(v4)
  (v7: @@test::A, v8: @test::A) <- struct_destructure(v6)
End:
  Match(match_enum(v7) {
    A::One(v9) => blk1,
    A::Two(v10) => blk5,
    A::Three(v11) => blk10,
  })

blk1:
Statements:
End:
  Match(match_enum(v8) {
    A::One(v12) => blk2,
    A::Two(v13) => blk3,
    A::Three(v14) => blk4,
  })

blk2:
Statements:
  (v15: core::felt252) <- 1
End:
  Return(v15)

blk3:
Statements:
End:
  Goto(blk13, {})

blk4:
Statements:
End:
  Goto(blk15, {})

blk5:
Statements:
End:
  Match(match_enum(v8) {
    A::One(v16) => blk6,
    A::Two(v17) => blk7,
    A::Three(v18) => blk8,
  })

blk6:
Statements:
  (v19: @@core::felt252, v20: @@core::felt252) <- struct_destructure(v10)
  (v21: @core::felt252) <- desnap(v19)
  (v22: core::felt252) <- desnap(v21)
  (v23: core::felt252) <- 3
  (v24: core::felt252) <- core::felt252_add(v22, v23)
End:
  Return(v24)

blk7:
Statements:
End:
  Goto(blk9, {})

blk8:
Statements:
End:
  Goto(blk9, {})

blk9:
Statements:
  (v25: core::felt252) <- 2
End:
  Return(v25)

blk10:
Statements:
End:
  Match(match_enum(v8) {
    A::One(v26) => blk11,
    A::Two(v27) => blk12,
    A::Three(v28) => blk14,
  })

blk11:
Statements:
End:
  Goto(blk13, {})

blk12:
Statements:
End:
  Goto(blk13, {})

blk13:
Statements:
  (v29: core::felt252) <- 6
End:
  Return(v29)

blk14:
Statements:
End:
  Goto(blk15, {})

blk15:
Statements:
  (v30: core::felt252) <- 3
End:
  Return(v30)

//! > ==========================================================================

//! > Test match on enum tuples missing arms.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A, b: A) -> felt252 {
    match (a, b) {
        (A::Two, A::One) => 5,
        (A::Two, _) => 2,
        (A::One(_), A::One(_)) => 1,
        (_, A::Three(_)) => 3,
        (_, A::Four) => 4,
    }
}

//! > function_name
foo

//! > module_code
#[derive(Copy, Drop)]
enum A {
    One: felt252,
    Two: (felt252, felt252),
    Three: (),
    Four: (),
}

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Missing match arm: `(One, Two)` not covered.
 --> lib.cairo:9:11
    match (a, b) {
          ^****^

error: Missing match arm: `(Three, One)` not covered.
 --> lib.cairo:9:11
    match (a, b) {
          ^****^

error: Missing match arm: `(Three, Two)` not covered.
 --> lib.cairo:9:11
    match (a, b) {
          ^****^

error: Missing match arm: `(Four, One)` not covered.
 --> lib.cairo:9:11
    match (a, b) {
          ^****^

error: Missing match arm: `(Four, Two)` not covered.
 --> lib.cairo:9:11
    match (a, b) {
          ^****^

//! > lowering_flat
Parameters: v0: test::A, v1: test::A

//! > ==========================================================================

//! > Test match on enum tuples with inner tuples.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A, b: A) -> felt252 {
    match (a, (a, b)) {
        (A::Two, (A::One, A::One)) => 8,
        _ => 4,
    }
}

//! > function_name
foo

//! > module_code
#[derive(Copy, Drop)]
enum A {
    One: felt252,
    Two: (felt252, felt252),
    Three: (),
    Four: (),
}

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unsupported matched value. Currently, match on tuples only supports enums as tuple members.
 --> lib.cairo:9:11
    match (a, (a, b)) {
          ^*********^

//! > lowering_flat
Parameters: v0: test::A, v1: test::A

//! > ==========================================================================

//! > Test match on enum tuples extern.

//! > test_runner_name
test_function_lowering

//! > function
fn foo(a: A) -> felt252 {
    match (a, get_bool()) {
        (A::Two, true) => 5,
        (A::Two, _) => 2,
        (A::One(_), false) => 1,
        (_, _) => 6,
    }
}

//! > function_name
foo

//! > module_code
enum A {
    One: felt252,
    Two: (felt252, felt252),
    Three: (),
    Four: (),
}
extern fn get_bool() -> bool nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: test::A
blk0 (root):
Statements:
End:
  Match(match test::get_bool() {
    bool::False => blk1,
    bool::True => blk2,
  })

blk1:
Statements:
  (v1: ()) <- struct_construct()
  (v2: core::bool) <- bool::False(v1)
End:
  Goto(blk3, {v2 -> v3})

blk2:
Statements:
  (v4: ()) <- struct_construct()
  (v5: core::bool) <- bool::True(v4)
End:
  Goto(blk3, {v5 -> v3})

blk3:
Statements:
End:
  Match(match_enum(v0) {
    A::One(v6) => blk4,
    A::Two(v7) => blk7,
    A::Three(v8) => blk10,
    A::Four(v9) => blk13,
  })

blk4:
Statements:
End:
  Match(match_enum(v3) {
    bool::False(v10) => blk5,
    bool::True(v11) => blk6,
  })

blk5:
Statements:
  (v12: core::felt252) <- 1
End:
  Return(v12)

blk6:
Statements:
End:
  Goto(blk16, {})

blk7:
Statements:
End:
  Match(match_enum(v3) {
    bool::False(v13) => blk8,
    bool::True(v14) => blk9,
  })

blk8:
Statements:
  (v15: core::felt252) <- 2
End:
  Return(v15)

blk9:
Statements:
  (v16: core::felt252) <- 5
End:
  Return(v16)

blk10:
Statements:
End:
  Match(match_enum(v3) {
    bool::False(v17) => blk11,
    bool::True(v18) => blk12,
  })

blk11:
Statements:
End:
  Goto(blk16, {})

blk12:
Statements:
End:
  Goto(blk16, {})

blk13:
Statements:
End:
  Match(match_enum(v3) {
    bool::False(v19) => blk14,
    bool::True(v20) => blk15,
  })

blk14:
Statements:
End:
  Goto(blk16, {})

blk15:
Statements:
End:
  Goto(blk16, {})

blk16:
Statements:
  (v21: core::felt252) <- 6
End:
  Return(v21)

//! > ==========================================================================

//! > Test match unsupported type.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    match 5_u256 {
        0 => 1,
        _ => 2
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics
error: Unsupported matched type. Type: `core::integer::u256`.
 --> lib.cairo:2:11
    match 5_u256 {
          ^****^

//! > lowering_flat
Parameters:

//! > ==========================================================================

//! > Test match ints optimization.

//! > test_runner_name
test_function_lowering

//! > function
fn foo() -> felt252 {
    match 5_u32 {
        0 => 1,
        1 => 2,
        2 => 3,
        3 => 4,
        4 => 5,
        5 => 6,
        6 => 7,
        _ => 8
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters: v0: core::RangeCheck
blk0 (root):
Statements:
  (v1: core::integer::u32) <- 5
End:
  Match(match core::integer::downcast::<core::integer::u32, core::internal::BoundedInt::<0, 6>>(v0, v1) {
    Option::Some(v2, v3) => blk1,
    Option::None(v4) => blk9,
  })

blk1:
Statements:
End:
  Match(match_enum.(v3) {
    0(v5) => blk2,
    1(v6) => blk3,
    2(v7) => blk4,
    3(v8) => blk5,
    4(v9) => blk6,
    5(v10) => blk7,
    6(v11) => blk8,
  })

blk2:
Statements:
  (v12: core::felt252) <- 1
End:
  Return(v2, v12)

blk3:
Statements:
  (v13: core::felt252) <- 2
End:
  Return(v2, v13)

blk4:
Statements:
  (v14: core::felt252) <- 3
End:
  Return(v2, v14)

blk5:
Statements:
  (v15: core::felt252) <- 4
End:
  Return(v2, v15)

blk6:
Statements:
  (v16: core::felt252) <- 5
End:
  Return(v2, v16)

blk7:
Statements:
  (v17: core::felt252) <- 6
End:
  Return(v2, v17)

blk8:
Statements:
  (v18: core::felt252) <- 7
End:
  Return(v2, v18)

blk9:
Statements:
  (v19: core::felt252) <- 8
End:
  Return(v4, v19)
