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

Structs inserted from comptime attributes can't be referred to from existing function signatures #5926

Open
jfecher opened this issue Sep 4, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@jfecher
Copy link
Contributor

jfecher commented Sep 4, 2024

Aim

#[make_struct]
fn foo() {}

comptime fn make_struct(_f: FunctionDefinition) -> Quoted {
    quote {
        struct MyStruct {}
    }
}

// Error: No type "MyStruct" in scope
fn bar(s: MyStruct) { ... }

Expected Behavior

The program to resolve & type check correctly

Bug

The compiler issues an error stating that MyType is not in scope.
This is because function signatures are resolved before attributes are run, and thus before the new type is inserted into the program.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@jfecher jfecher added the bug Something isn't working label Sep 4, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 4, 2024
github-merge-queue bot pushed a commit that referenced this issue Sep 4, 2024
…5927)

# Description

## Problem\*

Resolves #5913

## Summary\*

Allows inserting new structs and impls into the program from comptime
attributes.

## Additional Context

Inserting new structs wasn't allowed originally since functions wouldn't
be able to refer to them in their signature. This use case isn't needed
for aztec currently so I'm adding this feature now and we can look into
expanding it later. See #5926

## 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-merge-queue bot pushed a commit that referenced this issue Sep 6, 2024
# Description

## Problem\*

Resolves #5957

## Summary\*

Adds a generic to an existing struct.

## Additional Context

Due to the same reasoning in
#5926, existing code referring
to these structs won't see the generics on them. For now I've documented
to try to avoid this use case.

## Documentation\*

Check one:
- [ ] No documentation needed.
- [x] 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.

---------

Co-authored-by: Ary Borenszweig <asterite@gmail.com>
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
Status: 📋 Backlog
Development

No branches or pull requests

1 participant