You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[test]
fn test_mutable_ref()
{
let x = mutable_return_syntax_error();
assert(x[0] == 1);
}
fn mutable_return_syntax_error() -> [Field] {
let slice : &mut [Field] = &mut [];
slice = &mut (*slice).push_back(1);
for i in 0..2 { } // or if (...) { } // or { } -- same idea
*slice
}
Expected Behavior
I should be able to return the dereferenced slice.
Bug
Instead I get this bug:
If I fix the scope by adding a semicolon to the end of {} block like so:
fn mutable_return_syntax_error() -> [Field] {
let slice : &mut [Field] = &mut [];
slice = &mut (*slice).push_back(1);
for i in 0..2 { }; // or if (...) { } // or { } -- same idea
*slice
}
I will instead get this panic in SSA:
Message: internal error: entered unreachable code: Cannot assign to a variable without a reference
Location: compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs:662
To Reproduce
Copy the snippet in the issue over to a Noir program.
Run nargo test
Installation Method
Compiled from source
Nargo Version
nargo 0.15.0 (git version hash: 9854416, is dirty: true)
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered:
It turns out the panic was from slice not being declared as mutable. Normally you can mutate variables of type &mut T even if the variable itself is not declared as mutable - but crucially to mutate them you need to dereference them on the lhs of an assignment. Swapping out the reference to another reference as in this example should not have been possible, so the panic was correct and we were missing an extra check for when a variable can be mutated.
Aim
I want to be able to run this test:
Expected Behavior
I should be able to return the dereferenced slice.
Bug
Instead I get this bug:

If I fix the scope by adding a semicolon to the end of
{}
block like so:I will instead get this panic in SSA:
To Reproduce
nargo test
Installation Method
Compiled from source
Nargo Version
nargo 0.15.0 (git version hash: 9854416, is dirty: true)
Additional Context
No response
Would you like to submit a PR for this Issue?
No
Support Needs
No response
The text was updated successfully, but these errors were encountered: