Skip to content

Commit

Permalink
fix(ssa refactor): Fix panic in acir-gen from multiplying values of d…
Browse files Browse the repository at this point in the history
…ifferent types (#1769)

* Merge array values

* Remove redundant clone

* Fix merge values of different types bug
  • Loading branch information
jfecher authored Jun 21, 2023
1 parent 861e42c commit 1f9a132
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/noirc_evaluator/src/ssa_refactor/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,17 @@ impl<'f> Context<'f> {
else_value: ValueId,
) -> ValueId {
let block = self.inserter.function.entry_block();
let then_type = self.inserter.function.dfg.type_of_value(then_value);
let else_type = self.inserter.function.dfg.type_of_value(else_value);
assert_eq!(
then_type, else_type,
"Expected values merged to be of the same type but found {then_type} and {else_type}"
);

// We must cast the bool conditions to the actual numeric type used by each value.
let then_condition = self.insert_instruction(Instruction::Cast(then_condition, then_type));
let else_condition = self.insert_instruction(Instruction::Cast(else_condition, else_type));

let mul = Instruction::binary(BinaryOp::Mul, then_condition, then_value);
let then_value =
self.inserter.function.dfg.insert_instruction_and_results(mul, block, None).first();
Expand Down

0 comments on commit 1f9a132

Please sign in to comment.