Skip to content

Commit

Permalink
fix: Fix auto-deref operations assigning the wrong result type (#1904)
Browse files Browse the repository at this point in the history
Fix 1899
  • Loading branch information
jfecher authored Jul 10, 2023
1 parent 3972410 commit 827f78c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ fn main(mut x: Field) {
add1(&mut x);
assert(x == 3);

// https://github.com/noir-lang/noir/issues/1899
// let mut s = S { y: x };
// s.add2();
// assert(s.y == 5);
let mut s = S { y: x };
s.add2();
assert(s.y == 5);

// Test that normal mutable variables are still copied
let mut a = 0;
Expand Down
6 changes: 3 additions & 3 deletions crates/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,8 @@ impl<'interner> TypeChecker<'interner> {
operator: crate::UnaryOp::Dereference,
rhs: old_lhs,
}));
this.interner.push_expr_type(access_lhs, lhs_type);
this.interner.push_expr_type(&old_lhs, element);
this.interner.push_expr_type(&old_lhs, lhs_type);
this.interner.push_expr_type(access_lhs, element);
};

match self.check_field_access(&lhs_type, &access.rhs.0.contents, span, dereference_lhs) {
Expand Down Expand Up @@ -939,7 +939,7 @@ impl<'interner> TypeChecker<'interner> {
Type::MutableReference(Box::new(rhs_type.follow_bindings()))
}
crate::UnaryOp::Dereference => {
let element_type = Type::type_variable(self.interner.next_type_variable_id());
let element_type = self.interner.next_type_variable();
unify(Type::MutableReference(Box::new(element_type.clone())));
element_type
}
Expand Down

0 comments on commit 827f78c

Please sign in to comment.