//! > Test boolean if.
//! > test_runner_name
test_function_lowering
//! > function
fn foo(flag: bool) -> Option<A>{
let a = A{};
if flag {
Option::Some(a)
} else {
Option::None
}
}
//! > function_name
foo
//! > module_code
use integer::u128_overflowing_add;
struct A {}
impl ADestruct of Destruct::<A> {
fn destruct(self: A) nopanic {
// Use RangeCheck, a previously unused implicit.
u128_overflowing_add(1_u128, 2_u128);
}
}
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters: v9: core::RangeCheck, v0: core::bool
blk0 (root):
Statements:
(v1: test::A) <- struct_construct()
End:
Match(match_enum(v0) {
bool::False(v4) => blk1,
bool::True(v2) => blk2,
})
blk1:
Statements:
(v10: core::RangeCheck, v8: ()) <- test::ADestruct::destruct(v9, v1)
(v5: ()) <- struct_construct()
(v6: core::option::Option::<test::A>) <- Option::None(v5)
End:
Goto(blk3, {v10 -> v11, v6 -> v7})
blk2:
Statements:
(v3: core::option::Option::<test::A>) <- Option::Some(v1)
End:
Goto(blk3, {v9 -> v11, v3 -> v7})
blk3:
Statements:
End:
Return(v11, v7)
//! > ==========================================================================
//! > Test dict destruct through panic.
//! > test_runner_name
test_function_lowering
//! > function
fn foo(d: Felt252Dict<felt252>){
get_total_signed_weight(d);
}
//! > function_name
foo
//! > module_code
fn get_total_signed_weight(used_keys: Felt252Dict<felt252>) -> u128 { 1_u128 }
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters: v5: core::RangeCheck, v6: core::SegmentArena, v7: core::gas::GasBuiltin, v0: core::dict::Felt252Dict::<core::felt252>
blk0 (root):
Statements:
(v8: core::RangeCheck, v9: core::SegmentArena, v10: core::gas::GasBuiltin, v4: ()) <- core::dict::Felt252DictDestruct::<core::felt252, core::felt252Drop, core::Felt252Felt252DictValue>::destruct(v5, v6, v7, v0)
(v2: ()) <- struct_construct()
End:
Return(v8, v9, v10, v2)
//! > ==========================================================================
//! > Test panic destruct.
//! > test_runner_name
test_function_lowering
//! > function
fn foo(d: A){
may_panic();
may_panic();
panic_with_felt252('123');
}
//! > function_name
foo
//! > module_code
fn may_panic() {
panic_with_felt252('123');
}
struct A {}
impl APanicDestruct of PanicDestruct<A> {
fn panic_destruct(self: A, ref panic: Panic) nopanic {
let A {} = self;
}
}
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > lowering_flat
Parameters: v0: test::A
blk0 (root):
Statements:
(v13: core::panics::PanicResult::<((),)>) <- test::may_panic()
End:
Match(match_enum(v13) {
PanicResult::Ok(v14) => blk1,
PanicResult::Err(v16) => blk4,
})
blk1:
Statements:
(v18: core::panics::PanicResult::<((),)>) <- test::may_panic()
End:
Match(match_enum(v18) {
PanicResult::Ok(v19) => blk2,
PanicResult::Err(v21) => blk3,
})
blk2:
Statements:
(v10: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
(v3: core::felt252) <- 3224115u
(v11: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v10, v3)
(v8: core::panics::Panic) <- struct_construct()
(v8: core::panics::Panic, v24: ()) <- test::APanicDestruct::panic_destruct(v8, v0)
(v9: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v8, v11)
(v17: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v9)
End:
Return(v17)
blk3:
Statements:
(v26: core::panics::Panic, v27: core::array::Array::<core::felt252>) <- struct_destructure(v21)
(v26: core::panics::Panic, v28: ()) <- test::APanicDestruct::panic_destruct(v26, v0)
(v21: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v26, v27)
(v23: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v21)
End:
Return(v23)
blk4:
Statements:
(v30: core::panics::Panic, v31: core::array::Array::<core::felt252>) <- struct_destructure(v16)
(v30: core::panics::Panic, v32: ()) <- test::APanicDestruct::panic_destruct(v30, v0)
(v16: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v30, v31)
(v22: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v16)
End:
Return(v22)