Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: maintain correct type when simplifying x ^ x #4082

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions test_programs/noir_test_success/regression_4080/Nargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[package]
name = "regression_4080"
type = "bin"
authors = [""]
[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x = "5"
8 changes: 8 additions & 0 deletions test_programs/noir_test_success/regression_4080/src/main.nr
Original file line number Diff line number Diff line change
@@ -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);
}
Loading