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

Error: nested struct member access #1315

Closed
iAmMichaelConnor opened this issue May 8, 2023 · 1 comment · Fixed by #1317 or #1279
Closed

Error: nested struct member access #1315

iAmMichaelConnor opened this issue May 8, 2023 · 1 comment · Fixed by #1317 or #1279
Assignees
Labels
bug Something isn't working

Comments

@iAmMichaelConnor
Copy link
Collaborator

iAmMichaelConnor commented May 8, 2023

Aim

I was actually trying to write a minimal example for a different bug, but found this on my journey:

    struct A<T> {
        b: T,
    }

    impl<T> A<T> {
        fn new(b: T) -> Self {
            A { b }
        }
    }

    struct B<T> {
        c: T,
    }

    impl<T> B<T> {
        fn new(c: T) -> Self {
            B { c }
        }
    }

    fn main (c: Field, d: Field) -> pub Field {
        let mut b = B::new(c);
        let mut a = A::new(b);

        a.b.c *= d;
        a.b.c
    }
error: Type B<Field> has no member named c
   ┌─ /mnt/user-data/mike/packages/yarn-project/noir-contracts/src/contracts/zk_nft_contract/src/main.nr:46:13
   │
46 │         a.b.c *= d;
   │             -

error: aborting due to 1 previous errors
Error: Failed to compile circuit

Location:
    crates/nargo_cli/src/cli/mod.rs:71:5

Type B definitely has a member named c, so maybe it's confused, somehow?

Now, we can fix this by doing:

    fn main (c: Field, d: Field) -> pub Field {
        let mut b = B::new(c);
        let mut a = A::new(b);
        
        let mut ab = a.b;
        ab.c *= d;
        ab.c
    }

Which makes me think maybe nested struct access is broken?

Installation method

noirup

Nargo version

nargo 0.4.1 (git version hash: 3d2233d, is dirty: false)

@noir-lang/noir_wasm version

v0.4.1

@iAmMichaelConnor iAmMichaelConnor added the bug Something isn't working label May 8, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir May 8, 2023
@iAmMichaelConnor
Copy link
Collaborator Author

Note: #1316 was the issue I was actually aiming for, which is why there are generics in this example. You might be able to trim the generics from this issue, and still cause the bug. I haven't tried.

jfecher added a commit that referenced this issue May 8, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir May 8, 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
2 participants