//! > Check that literals are moved to the right arm.
//! > test_runner_name
test_reorder_statements
//! > function
fn foo() -> felt252 {
let opt = get_option();
let unused = 17;
let unused2 = ();
let one = 1;
let two = 2;
let three = 3;
match opt {
Option::Some(_) => one + two,
Option::None => {
let four = 4;
match opt {
Option::Some(_) => three + four,
Option::None => one,
}
}
}
}
//! > function_name
foo
//! > module_code
extern fn get_option() -> Option<u16> nopanic;
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > before
Parameters:
blk0 (root):
Statements:
End:
Match(match test::get_option() {
Option::Some(v0) => blk1,
Option::None => blk2,
})
blk1:
Statements:
(v1: core::option::Option::<core::integer::u16>) <- Option::Some(v0)
End:
Goto(blk3, {v1 -> v4})
blk2:
Statements:
(v2: ()) <- struct_construct()
(v3: core::option::Option::<core::integer::u16>) <- Option::None(v2)
End:
Goto(blk3, {v3 -> v4})
blk3:
Statements:
(v5: core::felt252) <- 17u
(v6: ()) <- struct_construct()
(v7: core::felt252) <- 1u
(v8: core::felt252) <- 2u
(v9: core::felt252) <- 3u
End:
Match(match_enum(v4) {
Option::Some(v10) => blk4,
Option::None(v12) => blk5,
})
blk4:
Statements:
(v19: core::felt252) <- core::felt252_add(v7, v8)
End:
Goto(blk9, {v19 -> v18})
blk5:
Statements:
(v13: core::felt252) <- 4u
End:
Match(match_enum(v4) {
Option::Some(v14) => blk6,
Option::None(v16) => blk7,
})
blk6:
Statements:
(v20: core::felt252) <- core::felt252_add(v9, v13)
End:
Goto(blk8, {v20 -> v17})
blk7:
Statements:
End:
Goto(blk8, {v7 -> v17})
blk8:
Statements:
End:
Goto(blk9, {v17 -> v18})
blk9:
Statements:
End:
Return(v18)
//! > after
Parameters:
blk0 (root):
Statements:
End:
Match(match test::get_option() {
Option::Some(v0) => blk1,
Option::None => blk2,
})
blk1:
Statements:
(v1: core::option::Option::<core::integer::u16>) <- Option::Some(v0)
End:
Goto(blk3, {v1 -> v4})
blk2:
Statements:
(v2: ()) <- struct_construct()
(v3: core::option::Option::<core::integer::u16>) <- Option::None(v2)
End:
Goto(blk3, {v3 -> v4})
blk3:
Statements:
(v7: core::felt252) <- 1u
End:
Match(match_enum(v4) {
Option::Some(v10) => blk4,
Option::None(v12) => blk5,
})
blk4:
Statements:
(v8: core::felt252) <- 2u
(v19: core::felt252) <- core::felt252_add(v7, v8)
End:
Goto(blk9, {v19 -> v18})
blk5:
Statements:
End:
Match(match_enum(v4) {
Option::Some(v14) => blk6,
Option::None(v16) => blk7,
})
blk6:
Statements:
(v9: core::felt252) <- 3u
(v13: core::felt252) <- 4u
(v20: core::felt252) <- core::felt252_add(v9, v13)
End:
Goto(blk8, {v20 -> v17})
blk7:
Statements:
End:
Goto(blk8, {v7 -> v17})
blk8:
Statements:
End:
Goto(blk9, {v17 -> v18})
blk9:
Statements:
End:
Return(v18)
//! > ==========================================================================
//! > Check that not statements are moved to the right arm or removed.
//! > test_runner_name
test_reorder_statements
//! > function
fn foo() {
let a = true;
let b = !a;
!!a;
match get_option() {
Option::Some(_) => a,
Option::None => false ^ b,
};
}
//! > function_name
foo
//! > module_code
extern fn get_option() -> Option<u16> nopanic;
//! > semantic_diagnostics
//! > lowering_diagnostics
//! > before
Parameters:
blk0 (root):
Statements:
(v0: ()) <- struct_construct()
(v1: core::bool) <- bool::True(v0)
(v11: core::bool) <- core::bool_not_impl(v1)
(v13: core::bool) <- core::bool_not_impl(v1)
(v14: core::bool) <- core::bool_not_impl(v13)
End:
Match(match test::get_option() {
Option::Some(v5) => blk1,
Option::None => blk2,
})
blk1:
Statements:
End:
Goto(blk3, {})
blk2:
Statements:
(v6: ()) <- struct_construct()
(v7: core::bool) <- bool::False(v6)
(v12: core::bool) <- core::bool_xor_impl(v7, v11)
End:
Goto(blk3, {})
blk3:
Statements:
(v10: ()) <- struct_construct()
End:
Return(v10)
//! > after
Parameters:
blk0 (root):
Statements:
End:
Match(match test::get_option() {
Option::Some(v5) => blk1,
Option::None => blk2,
})
blk1:
Statements:
End:
Goto(blk3, {})
blk2:
Statements:
(v0: ()) <- struct_construct()
(v1: core::bool) <- bool::True(v0)
(v11: core::bool) <- core::bool_not_impl(v1)
(v6: ()) <- struct_construct()
(v7: core::bool) <- bool::False(v6)
(v12: core::bool) <- core::bool_xor_impl(v7, v11)
End:
Goto(blk3, {})
blk3:
Statements:
(v10: ()) <- struct_construct()
End:
Return(v10)