//! > Test for.

//! > test_runner_name
test_generated_function

//! > function_code
fn foo() -> felt252 {
    let mut x = 1;
    let y = x + 1;
    let mut iter = array![10, 11, 12, 13_felt252].span();
    for _x in iter {
        x = x + y;
    }
    x
}

//! > function_name
foo

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 1
  (v1: core::felt252) <- 1
  (v2: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v3: core::array::Array::<core::felt252>) <- core::array::ArrayImpl::<core::felt252>::new()
  (v4: core::felt252) <- 10
  (v6: core::array::Array::<core::felt252>, v5: ()) <- core::array::ArrayImpl::<core::felt252>::append(v3, v4)
  (v7: core::felt252) <- 11
  (v9: core::array::Array::<core::felt252>, v8: ()) <- core::array::ArrayImpl::<core::felt252>::append(v6, v7)
  (v10: core::felt252) <- 12
  (v12: core::array::Array::<core::felt252>, v11: ()) <- core::array::ArrayImpl::<core::felt252>::append(v9, v10)
  (v13: core::felt252) <- 13
  (v15: core::array::Array::<core::felt252>, v14: ()) <- core::array::ArrayImpl::<core::felt252>::append(v12, v13)
  (v16: core::array::Array::<core::felt252>, v17: @core::array::Array::<core::felt252>) <- snapshot(v15)
  (v18: core::array::Span::<core::felt252>) <- core::array::ArrayToSpan::<core::felt252>::span(v17)
  (v19: core::array::SpanIter::<core::felt252>) <- core::array::SpanIntoIterator::<core::felt252>::into_iter(v18)
  (v21: core::array::SpanIter::<core::felt252>, v22: core::felt252, v20: ()) <- test::foo[118-164](v19, v0, v2)
End:
  Return(v22)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 10
  (v4: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v5: core::felt252) <- 11
  (v6: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v4, v5)
  (v7: core::felt252) <- 12
  (v8: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v6, v7)
  (v9: core::felt252) <- 13
  (v10: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v8, v9)
  (v11: core::array::Array::<core::felt252>, v12: @core::array::Array::<core::felt252>) <- snapshot(v10)
  (v13: core::array::Span::<core::felt252>) <- struct_construct(v12)
  (v14: core::array::SpanIter::<core::felt252>) <- struct_construct(v13)
  (v15: core::RangeCheck, v16: core::gas::GasBuiltin, v17: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- test::foo[118-164]{NotSpecialized, 1, 2, }(v0, v1, v14)
End:
  Match(match_enum(v17) {
    PanicResult::Ok(v18) => blk1,
    PanicResult::Err(v19) => blk2,
  })

blk1:
Statements:
  (v20: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v16)
  (v21: core::array::SpanIter::<core::felt252>, v22: core::felt252, v23: ()) <- struct_destructure(v18)
  (v24: (core::felt252,)) <- struct_construct(v22)
  (v25: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v24)
End:
  Return(v15, v20, v25)

blk2:
Statements:
  (v26: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v19)
End:
  Return(v15, v16, v26)


Generated loop lowering for source location:
      for _x in iter {
 _____^
|         x = x + y;
|     }
|_____^

Parameters: v0: core::array::SpanIter::<core::felt252>, v1: core::felt252, v2: core::felt252
blk0 (root):
Statements:
  (v4: core::array::SpanIter::<core::felt252>, v3: core::option::Option::<@core::felt252>) <- core::array::SpanIterator::<core::felt252>::next(v0)
End:
  Match(match_enum(v3) {
    Option::Some(v5) => blk1,
    Option::None(v10) => blk2,
  })

blk1:
Statements:
  (v6: core::felt252) <- core::Felt252Add::add(v1, v2)
  (v8: core::array::SpanIter::<core::felt252>, v9: core::felt252, v7: ()) <- test::foo[118-164](v4, v6, v2)
End:
  Return(v8, v9, v7)

blk2:
Statements:
  (v11: ()) <- struct_construct()
End:
  Return(v4, v1, v11)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::array::SpanIter::<core::felt252>, v3: core::felt252, v4: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v5, v6) => blk1,
    Option::None(v7, v8) => blk4,
  })

blk1:
Statements:
  (v9: core::array::Span::<core::felt252>) <- struct_destructure(v2)
  (v10: @core::array::Array::<core::felt252>) <- struct_destructure(v9)
End:
  Match(match core::array::array_snapshot_pop_front::<core::felt252>(v10) {
    Option::Some(v11, v12) => blk2,
    Option::None(v13) => blk3,
  })

blk2:
Statements:
  (v14: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v6)
  (v15: core::felt252) <- core::felt252_add(v3, v4)
  (v16: core::array::Span::<core::felt252>) <- struct_construct(v11)
  (v17: core::array::SpanIter::<core::felt252>) <- struct_construct(v16)
  (v18: core::RangeCheck, v19: core::gas::GasBuiltin, v20: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- test::foo[118-164](v5, v14, v17, v15, v4)
End:
  Return(v18, v19, v20)

blk3:
Statements:
  (v21: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v6)
  (v22: core::array::Span::<core::felt252>) <- struct_construct(v13)
  (v23: core::array::SpanIter::<core::felt252>) <- struct_construct(v22)
  (v24: ()) <- struct_construct()
  (v25: (core::array::SpanIter::<core::felt252>, core::felt252, ())) <- struct_construct(v23, v3, v24)
  (v26: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- PanicResult::Ok(v25)
End:
  Return(v5, v21, v26)

blk4:
Statements:
  (v27: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v28: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- PanicResult::Err(v27)
End:
  Return(v7, v8, v28)


Final lowering of specialized call "test::foo[118-164]{NotSpecialized, 1, 2, }":
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::array::SpanIter::<core::felt252>
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk4,
  })

blk1:
Statements:
  (v7: core::array::Span::<core::felt252>) <- struct_destructure(v2)
  (v8: @core::array::Array::<core::felt252>) <- struct_destructure(v7)
End:
  Match(match core::array::array_snapshot_pop_front::<core::felt252>(v8) {
    Option::Some(v9, v10) => blk2,
    Option::None(v11) => blk3,
  })

blk2:
Statements:
  (v12: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v13: core::felt252) <- 3
  (v14: core::array::Span::<core::felt252>) <- struct_construct(v9)
  (v15: core::array::SpanIter::<core::felt252>) <- struct_construct(v14)
  (v16: core::RangeCheck, v17: core::gas::GasBuiltin, v18: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- test::foo[118-164]{NotSpecialized, NotSpecialized, 2, }(v3, v12, v15, v13)
End:
  Return(v16, v17, v18)

blk3:
Statements:
  (v19: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v4)
  (v20: core::felt252) <- 1
  (v21: core::array::Span::<core::felt252>) <- struct_construct(v11)
  (v22: core::array::SpanIter::<core::felt252>) <- struct_construct(v21)
  (v23: ()) <- struct_construct()
  (v24: (core::array::SpanIter::<core::felt252>, core::felt252, ())) <- struct_construct(v22, v20, v23)
  (v25: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- PanicResult::Ok(v24)
End:
  Return(v3, v19, v25)

blk4:
Statements:
  (v26: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v27: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::felt252, ())>) <- PanicResult::Err(v26)
End:
  Return(v5, v6, v27)

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

//! > Test calling function with generics Self.

//! > test_runner_name
test_generated_function

//! > function_code
fn foo() {
    let v = 1_u32;
    v.foo()
}

//! > function_name
foo

//! > module_code
trait MyTrait<T, +Drop<T>, +Copy<T>, +Add<T>> {
    #[inline(never)]
    fn bar(self: T) -> T {
        self
    }

    fn foo(self: T) {
        for _ in 0_u32..5 {
            Self::bar(self) + Self::bar(self);
        }
    }
}

fn bar<T, +Drop<T>, +Copy<T>, +Add<T>>(v: T) {
    let v = 1_u32;
    v.foo()
}

impl MyImpl of MyTrait<u32> {}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u32) <- 1
  (v1: ()) <- test::MyImpl::foo(v0)
End:
  Return(v1)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::integer::u32) <- 1
  (v3: core::integer::u32) <- 0
  (v4: core::integer::u32) <- 5
End:
  Match(match core::ops::range::internal::int_range_try_new::<core::integer::u32>(v0, v3, v4) {
    Result::Ok(v5, v6) => blk1,
    Result::Err(v7, v8) => blk2,
  })

blk1:
Statements:
  (v9: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v1)
End:
  Goto(blk3, {v5 -> v10, v9 -> v11, v6 -> v12})

blk2:
Statements:
  (v13: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v1)
End:
  Goto(blk3, {v7 -> v10, v13 -> v11, v8 -> v12})

blk3:
Statements:
  (v14: core::RangeCheck, v15: core::gas::GasBuiltin, v16: core::panics::PanicResult::<(core::ops::range::internal::IntRange::<core::integer::u32>, ())>) <- test::MyImpl::foo[23-108](v10, v11, v12, v2)
End:
  Match(match_enum(v16) {
    PanicResult::Ok(v17) => blk4,
    PanicResult::Err(v18) => blk5,
  })

blk4:
Statements:
  (v19: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v15)
  (v20: core::ops::range::internal::IntRange::<core::integer::u32>, v21: ()) <- struct_destructure(v17)
  (v22: ((),)) <- struct_construct(v21)
  (v23: core::panics::PanicResult::<((),)>) <- PanicResult::Ok(v22)
End:
  Return(v14, v19, v23)

blk5:
Statements:
  (v24: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v18)
End:
  Return(v14, v15, v24)

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

//! > Test for with deref before into_iter.

//! > test_runner_name
test_generated_function

//! > function_code
fn foo(a: Box<Span<felt252>>) -> Array<felt252> {
    let mut arr = array![];
    for b in a {
        arr.append(*b);
    }
    return arr;
}

//! > function_name
foo

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat

//! > lowering
Main:
Parameters: v0: core::box::Box::<core::array::Span::<core::felt252>>
blk0 (root):
Statements:
  (v1: core::array::Array::<core::felt252>) <- core::array::ArrayImpl::<core::felt252>::new()
  (v2: core::array::Span::<core::felt252>) <- core::box::BoxDeref::<core::array::Span::<core::felt252>>::deref(v0)
  (v3: core::array::SpanIter::<core::felt252>) <- core::array::SpanIntoIterator::<core::felt252>::into_iter(v2)
  (v5: core::array::SpanIter::<core::felt252>, v6: core::array::Array::<core::felt252>, v4: ()) <- test::foo[78-125](v3, v1)
End:
  Return(v6)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::box::Box::<core::array::Span::<core::felt252>>
blk0 (root):
Statements:
  (v3: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v4: core::array::Span::<core::felt252>) <- unbox(v2)
  (v5: core::array::SpanIter::<core::felt252>) <- struct_construct(v4)
  (v6: core::RangeCheck, v7: core::gas::GasBuiltin, v8: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- test::foo[78-125](v0, v1, v5, v3)
End:
  Match(match_enum(v8) {
    PanicResult::Ok(v9) => blk1,
    PanicResult::Err(v10) => blk2,
  })

blk1:
Statements:
  (v11: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v7)
  (v12: core::array::SpanIter::<core::felt252>, v13: core::array::Array::<core::felt252>, v14: ()) <- struct_destructure(v9)
  (v15: (core::array::Array::<core::felt252>,)) <- struct_construct(v13)
  (v16: core::panics::PanicResult::<(core::array::Array::<core::felt252>,)>) <- PanicResult::Ok(v15)
End:
  Return(v6, v11, v16)

blk2:
Statements:
  (v17: core::panics::PanicResult::<(core::array::Array::<core::felt252>,)>) <- PanicResult::Err(v10)
End:
  Return(v6, v7, v17)


Generated loop lowering for source location:
      for b in a {
 _____^
|         arr.append(*b);
|     }
|_____^

Parameters: v0: core::array::SpanIter::<core::felt252>, v1: core::array::Array::<core::felt252>
blk0 (root):
Statements:
  (v3: core::array::SpanIter::<core::felt252>, v2: core::option::Option::<@core::felt252>) <- core::array::SpanIterator::<core::felt252>::next(v0)
End:
  Match(match_enum(v2) {
    Option::Some(v4) => blk1,
    Option::None(v11) => blk2,
  })

blk1:
Statements:
  (v5: core::felt252) <- desnap(v4)
  (v7: core::array::Array::<core::felt252>, v6: ()) <- core::array::ArrayImpl::<core::felt252>::append(v1, v5)
  (v9: core::array::SpanIter::<core::felt252>, v10: core::array::Array::<core::felt252>, v8: ()) <- test::foo[78-125](v3, v7)
End:
  Return(v9, v10, v8)

blk2:
Statements:
  (v12: ()) <- struct_construct()
End:
  Return(v3, v1, v12)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::array::SpanIter::<core::felt252>, v3: core::array::Array::<core::felt252>
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v4, v5) => blk1,
    Option::None(v6, v7) => blk4,
  })

blk1:
Statements:
  (v8: core::array::Span::<core::felt252>) <- struct_destructure(v2)
  (v9: @core::array::Array::<core::felt252>) <- struct_destructure(v8)
End:
  Match(match core::array::array_snapshot_pop_front::<core::felt252>(v9) {
    Option::Some(v10, v11) => blk2,
    Option::None(v12) => blk3,
  })

blk2:
Statements:
  (v13: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v5)
  (v14: @core::felt252) <- unbox(v11)
  (v15: core::felt252) <- desnap(v14)
  (v16: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v3, v15)
  (v17: core::array::Span::<core::felt252>) <- struct_construct(v10)
  (v18: core::array::SpanIter::<core::felt252>) <- struct_construct(v17)
  (v19: core::RangeCheck, v20: core::gas::GasBuiltin, v21: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- test::foo[78-125](v4, v13, v18, v16)
End:
  Return(v19, v20, v21)

blk3:
Statements:
  (v22: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v5)
  (v23: core::array::Span::<core::felt252>) <- struct_construct(v12)
  (v24: core::array::SpanIter::<core::felt252>) <- struct_construct(v23)
  (v25: ()) <- struct_construct()
  (v26: (core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())) <- struct_construct(v24, v3, v25)
  (v27: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- PanicResult::Ok(v26)
End:
  Return(v4, v22, v27)

blk4:
Statements:
  (v28: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v29: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- PanicResult::Err(v28)
End:
  Return(v6, v7, v29)


Final lowering of specialized call "test::foo[78-125]":
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::array::SpanIter::<core::felt252>, v3: core::array::Array::<core::felt252>
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v4, v5) => blk1,
    Option::None(v6, v7) => blk4,
  })

blk1:
Statements:
  (v8: core::array::Span::<core::felt252>) <- struct_destructure(v2)
  (v9: @core::array::Array::<core::felt252>) <- struct_destructure(v8)
End:
  Match(match core::array::array_snapshot_pop_front::<core::felt252>(v9) {
    Option::Some(v10, v11) => blk2,
    Option::None(v12) => blk3,
  })

blk2:
Statements:
  (v13: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v5)
  (v14: @core::felt252) <- unbox(v11)
  (v15: core::felt252) <- desnap(v14)
  (v16: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v3, v15)
  (v17: core::array::Span::<core::felt252>) <- struct_construct(v10)
  (v18: core::array::SpanIter::<core::felt252>) <- struct_construct(v17)
  (v19: core::RangeCheck, v20: core::gas::GasBuiltin, v21: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- test::foo[78-125](v4, v13, v18, v16)
End:
  Return(v19, v20, v21)

blk3:
Statements:
  (v22: core::gas::GasBuiltin) <- core::gas::redeposit_gas(v5)
  (v23: core::array::Span::<core::felt252>) <- struct_construct(v12)
  (v24: core::array::SpanIter::<core::felt252>) <- struct_construct(v23)
  (v25: ()) <- struct_construct()
  (v26: (core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())) <- struct_construct(v24, v3, v25)
  (v27: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- PanicResult::Ok(v26)
End:
  Return(v4, v22, v27)

blk4:
Statements:
  (v28: (core::panics::Panic, core::array::Array::<core::felt252>)) <- core::panic_with_const_felt252::<375233589013918064796019>()
  (v29: core::panics::PanicResult::<(core::array::SpanIter::<core::felt252>, core::array::Array::<core::felt252>, ())>) <- PanicResult::Err(v28)
End:
  Return(v6, v7, v29)
