Merge pull request #466 from AleoHQ/fix/nested-mut-value

Fixes assignment of mutable variable to mutable variable
This commit is contained in:
Howard Wu 2020-12-07 20:41:58 -04:00 committed by GitHub
commit f841f2e348
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 0 deletions

View File

@ -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) { pub(crate) fn get_inner_mut(&mut self) {
if let ConstrainedValue::Mutable(inner) = self { if let ConstrainedValue::Mutable(inner) = self {
// Recursively remove `mut` keywords.
inner.get_inner_mut();
// Modify the value.
*self = *inner.clone() *self = *inner.clone()
} }
} }

View File

@ -0,0 +1,5 @@
function main () {
let mut x = 2u8;
let mut y = x;
let z = y / 2u8;
}

View File

@ -33,6 +33,14 @@ fn test_let_mut() {
assert_satisfied(program); 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] #[test]
fn test_const_fail() { fn test_const_fail() {
let bytes = include_bytes!("const.leo"); let bytes = include_bytes!("const.leo");