mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-19 15:41:36 +03:00
Merge pull request #466 from AleoHQ/fix/nested-mut-value
Fixes assignment of mutable variable to mutable variable
This commit is contained in:
commit
f841f2e348
@ -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()
|
||||
}
|
||||
}
|
||||
|
5
compiler/tests/mutability/let_mut_nested.leo
Normal file
5
compiler/tests/mutability/let_mut_nested.leo
Normal file
@ -0,0 +1,5 @@
|
||||
function main () {
|
||||
let mut x = 2u8;
|
||||
let mut y = x;
|
||||
let z = y / 2u8;
|
||||
}
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user