diff --git a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs index 457fe41de9..dbad562b6f 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/instruction.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/instruction.rs @@ -1002,7 +1002,7 @@ impl Binary { return SimplifyResult::SimplifiedTo(self.lhs); } if dfg.resolve(self.lhs) == dfg.resolve(self.rhs) { - let zero = dfg.make_constant(FieldElement::zero(), Type::bool()); + let zero = dfg.make_constant(FieldElement::zero(), operand_type); return SimplifyResult::SimplifiedTo(zero); } } diff --git a/test_programs/noir_test_success/regression_4080/Nargo.toml b/test_programs/noir_test_success/regression_4080/Nargo.toml new file mode 100644 index 0000000000..a38baf389d --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/Nargo.toml @@ -0,0 +1,5 @@ +[package] +name = "regression_4080" +type = "bin" +authors = [""] +[dependencies] diff --git a/test_programs/noir_test_success/regression_4080/Prover.toml b/test_programs/noir_test_success/regression_4080/Prover.toml new file mode 100644 index 0000000000..0e5dfd5638 --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/Prover.toml @@ -0,0 +1 @@ +x = "5" diff --git a/test_programs/noir_test_success/regression_4080/src/main.nr b/test_programs/noir_test_success/regression_4080/src/main.nr new file mode 100644 index 0000000000..781d3e33ea --- /dev/null +++ b/test_programs/noir_test_success/regression_4080/src/main.nr @@ -0,0 +1,8 @@ +// This test checks that `var^var` is assigned the correct type. +// https://github.com/noir-lang/noir/issues/4080 + +#[test(should_fail_with = "attempt to add with overflow")] +fn main() { + let var1: u8 = ((255 + 1) ^ (255 + 1)) - ((255 + 1) - (255 + 1)); + assert_eq(var1, 0); +}