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

Globals calling a static method on a struct in a different module fails to resolve #5271

Closed
TomAFrench opened this issue Jun 18, 2024 · 0 comments · Fixed by #5282
Closed
Labels
bug Something isn't working

Comments

@TomAFrench
Copy link
Member

Aim

I would like to create a global by calling a static method on a struct which is defined in another module.

My program is then

global some_wrapped_value: thing::FooStruct = thing::FooStruct::new();
mod thing {
    struct FooStruct {
        inner: Field
    }

    impl FooStruct {
        pub fn new() -> Self {
            FooStruct { inner: 0 }
        }
    }
}

Expected Behavior

This program should compile successfully with some_wrapped_value being equal to FooStruct { inner: 0 }.

Bug

Compilation fails with the error below:

$ nargo execute
error: Could not resolve 'FooStruct' in path
   ┌─ /home/tom/Programming/aztec/noir/test_programs/execution_success/global_consts/src/main.nr:80:13
   │
80 │             FooStruct { inner: 0 }
   │             ---------
   │

Aborting due to 1 previous error

To Reproduce

copy-paste above code into program with an empty fn main() {} and compile

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

This bug seems to specifically hit static methods on structs which are being referred to using full path as opposed to being imported into the current module as the following programs compile:

FooStruct is imported into current module:

global some_wrapped_value: FooStruct = FooStruct::new();
use thing::FooStruct;
mod thing {
    struct FooStruct {
        inner: Field
    }

    impl FooStruct {
        pub fn new() -> Self {
            FooStruct { inner: 0 }
        }
    }
}

some_wrapped_value is being initialized to be equal to a FooStruct constructed in the same module as where it is defined.

global some_wrapped_value: thing::FooStruct = thing::foo_thing;
mod thing {
    global foo_thing: FooStruct = FooStruct::new();

    struct FooStruct {
        inner: Field
    }

    impl FooStruct {
        pub fn new() -> Self {
            FooStruct { inner: 0 }
        }
    }
}

Installation Method

None

Nargo Version

No response

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@TomAFrench TomAFrench added the bug Something isn't working label Jun 18, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 18, 2024
@TomAFrench TomAFrench changed the title Calling a static method Globals calling a static method on a struct in a different module fails to resolve Jun 18, 2024
github-merge-queue bot pushed a commit that referenced this issue Jun 19, 2024
# Description

## Problem\*

Resolves #5271

## Summary\*

Lazily elaborating functions wasn't correct since the FuncMeta object
never stored the LocalModuleId carried by the set of unresolved
functions. This lead to lazily elaborated functions be elaborated in a
different module than intended.

## Additional Context

Lazily elaborated functions seem to no longer be necessary to run our
tests, nor to run the tests in aztec-nr so I've just removed them rather
than adding the additional fields to FuncMeta.

## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jun 19, 2024
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.

1 participant