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

Fixes assignment of mutable variable to mutable variable #466

Merged
merged 2 commits into from
Dec 8, 2020
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
7 changes: 7 additions & 0 deletions compiler/src/value/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,15 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedValue<F, G> {
}
}

///
/// Modifies the `self` [ConstrainedValue] so there are no `mut` keywords wrapping the `self` value.
///
pub(crate) fn get_inner_mut(&mut self) {
if let ConstrainedValue::Mutable(inner) = self {
// Recursively remove `mut` keywords.
inner.get_inner_mut();

// Modify the value.
*self = *inner.clone()
}
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/tests/mutability/let_mut_nested.leo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function main () {
let mut x = 2u8;
let mut y = x;
let z = y / 2u8;
}
8 changes: 8 additions & 0 deletions compiler/tests/mutability/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ fn test_let_mut() {
assert_satisfied(program);
}

#[test]
fn test_let_mut_nested() {
let bytes = include_bytes!("let_mut_nested.leo");
let program = parse_program(bytes).unwrap();

assert_satisfied(program);
}

#[test]
fn test_const_fail() {
let bytes = include_bytes!("const.leo");
Expand Down