@@ -161,6 +161,7 @@ pub fn simplify_program(mut program: Program) -> SimpleProgram {
161161 let mut array_manager = ArrayManager :: default ( ) ;
162162 let simplified_instructions = simplify_lines (
163163 & program. functions ,
164+ func. n_returned_vars ,
164165 & func. body ,
165166 & mut counters,
166167 & mut new_functions,
@@ -436,8 +437,10 @@ impl ArrayManager {
436437 }
437438}
438439
440+ #[ allow( clippy:: too_many_arguments) ]
439441fn simplify_lines (
440442 functions : & BTreeMap < String , Function > ,
443+ n_returned_vars : usize ,
441444 lines : & [ Line ] ,
442445 counters : & mut Counters ,
443446 new_functions : & mut BTreeMap < String , SimpleFunction > ,
@@ -458,6 +461,7 @@ fn simplify_lines(
458461 assert_eq ! ( * pattern, i, "match patterns should be consecutive, starting from 0" ) ;
459462 simple_arms. push ( simplify_lines (
460463 functions,
464+ n_returned_vars,
461465 statements,
462466 counters,
463467 new_functions,
@@ -610,6 +614,7 @@ fn simplify_lines(
610614 let mut array_manager_then = array_manager. clone ( ) ;
611615 let then_branch_simplified = simplify_lines (
612616 functions,
617+ n_returned_vars,
613618 then_branch,
614619 counters,
615620 new_functions,
@@ -622,6 +627,7 @@ fn simplify_lines(
622627
623628 let else_branch_simplified = simplify_lines (
624629 functions,
630+ n_returned_vars,
625631 else_branch,
626632 counters,
627633 new_functions,
@@ -672,6 +678,7 @@ fn simplify_lines(
672678 replace_vars_for_unroll ( & mut body_copy, iterator, unroll_index, i, & internal_variables) ;
673679 unrolled_lines. extend ( simplify_lines (
674680 functions,
681+ 0 ,
675682 & body_copy,
676683 counters,
677684 new_functions,
@@ -696,6 +703,7 @@ fn simplify_lines(
696703 array_manager. valid . clear ( ) ;
697704 let simplified_body = simplify_lines (
698705 functions,
706+ 0 ,
699707 body,
700708 counters,
701709 new_functions,
@@ -793,6 +801,11 @@ fn simplify_lines(
793801 }
794802 Line :: FunctionRet { return_data } => {
795803 assert ! ( !in_a_loop, "Function return inside a loop is not currently supported" ) ;
804+ assert ! (
805+ return_data. len( ) == n_returned_vars,
806+ "Wrong number of return values in return statement; expected {n_returned_vars} but got {}" ,
807+ return_data. len( )
808+ ) ;
796809 let simplified_return_data = return_data
797810 . iter ( )
798811 . map ( |ret| simplify_expr ( ret, & mut res, counters, array_manager, const_malloc) )
0 commit comments