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

Calling a nested method does not mutate the struct field #1887

Closed
jfecher opened this issue Jul 7, 2023 · 2 comments · Fixed by #2087
Closed

Calling a nested method does not mutate the struct field #1887

jfecher opened this issue Jul 7, 2023 · 2 comments · Fixed by #2087
Assignees
Labels
bug Something isn't working

Comments

@jfecher
Copy link
Contributor

jfecher commented Jul 7, 2023

Aim

Tried to prove and verify the following with --experimental-ssa:

struct Foo { bar: Bar }

struct Bar { x: Field }

impl Bar {
    fn mutate(&mut self) {
        self.x = 32;
    }
}

fn main() {
    let foo = &mut Foo { bar: Bar { x: 0 } };
    foo.bar.mutate();
    assert(foo.bar.x == 32);
}

Expected Behavior

Expected the code to prove and verify with foo.bar.x now equal to 32.

Bug

Due to . automatically dereferencing, the call to mutate is equivalent to

mutate(&mut (*foo).bar);

which mutates a copy of foo.bar rather than the original. So foo.bar.x would still equal 0 after the call to mutate, thus failing the assert.

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@jfecher jfecher added the bug Something isn't working label Jul 7, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 7, 2023
@kevaundray
Copy link
Contributor

@jfecher what's the status of this issue?

@jfecher
Copy link
Contributor Author

jfecher commented Jul 24, 2023

@kevaundray still open

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants