-
Notifications
You must be signed in to change notification settings - Fork 220
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
Mutable reference (within a struct) doesn't mutate (within a nested function call) #1961
Comments
If you modify the test assertion to pass (
|
The intended behavior of this is actually to not mutate the original. By dereferencing here you're copying the entire vec_wrapper into a new one. The intended solution is the commented out line
It is wrong - following rust's semantics you don't need a separate pointer-dereference operator like |
I just double-checked and using Thanks for all of the explanation, that's really helpful. |
@iAmMichaelConnor @kevaundray looks like this is a repeat of an older issue: #1887. I'm closing this one since the example is larger. |
Apologies for not making this one potato-themed.
I encountered a bug when migrating all of our Noir Contract examples to use mutable references.
All of the contracts compile (hooray!), but the typescript tests were throwing lots of errors when simulating.
I've tried to provide a minimal example. It's a bit messy, but it's neater than the 6 files that the original error came from!
The problem highlighted in this issue is that if you pass a value to a function as a mutable reference*, the value does get mutated.
*It's a bit more complicated than that... it's actually if you pass a value (which is a member of some struct) to a function by mutable reference, and then to another function by mutable reference, and then try to mutate the value, the value does not get mutated.
Compiling from source. Branch
master
.(*vec_wrapper).vec.push(value);
andvec_wrapper.vec.push(value);
are both accepted by the compiler. Isn't the first one the correct one? And the second one should fail because we haven't dereferencedvec_wrapper
? Would it be correct to sayvec_wrapper
has no membervec
; and only*vec_wrapper
has a membervec
? Or is that wrong?The text was updated successfully, but these errors were encountered: