diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs index 4f7ae88e6f..1e3503ccc3 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/mod.rs @@ -984,17 +984,22 @@ impl Context { lhs: AcirValue, rhs: AcirValue, read_from_index: &mut impl FnMut(BlockId, usize) -> Result, - ) -> Vec<(AcirVar, AcirVar)> { + ) -> Result, InternalError> { match (lhs, rhs) { - (AcirValue::Var(lhs, _), AcirValue::Var(rhs, _)) => vec![(lhs, rhs)], - (AcirValue::Array(lhs_values), AcirValue::Array(rhs_values)) => lhs_values - .into_iter() - .zip(rhs_values) - .flat_map(|(lhs, rhs)| { - get_var_equality_assertions(lhs, rhs, read_from_index) - }) - .collect(), - + (AcirValue::Var(lhs, _), AcirValue::Var(rhs, _)) => Ok(vec![(lhs, rhs)]), + (AcirValue::Array(lhs_values), AcirValue::Array(rhs_values)) => { + let var_equality_assertions = lhs_values + .into_iter() + .zip(rhs_values) + .map(|(lhs, rhs)| { + get_var_equality_assertions(lhs, rhs, read_from_index) + }) + .collect::, _>>()? + .into_iter() + .flatten() + .collect(); + Ok(var_equality_assertions) + } ( AcirValue::DynamicArray(AcirDynamicArray { block_id: lhs_block_id, @@ -1007,12 +1012,12 @@ impl Context { ) => { let mut var_equality_assertions = Vec::with_capacity(len); for i in 0..len { - let lhs_var = read_from_index(lhs_block_id, i).expect("temporary"); - let rhs_var = read_from_index(rhs_block_id, i).expect("temporary"); + let lhs_var = read_from_index(lhs_block_id, i)?; + let rhs_var = read_from_index(rhs_block_id, i)?; var_equality_assertions.push((lhs_var, rhs_var)); } - var_equality_assertions + Ok(var_equality_assertions) } _ => unreachable!("ICE: lhs and rhs should be of the same type"), } @@ -1030,7 +1035,7 @@ impl Context { }; for (lhs, rhs) in - get_var_equality_assertions(lhs, rhs, &mut read_dynamic_array_index) + get_var_equality_assertions(lhs, rhs, &mut read_dynamic_array_index)? { self.acir_context.assert_eq_var(lhs, rhs)?; }