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

Self doesn't resolve when calling static struct methods as Self::f #1791

Closed
shuklaayush opened this issue Jun 22, 2023 · 3 comments · Fixed by #5629
Closed

Self doesn't resolve when calling static struct methods as Self::f #1791

shuklaayush opened this issue Jun 22, 2023 · 3 comments · Fixed by #5629
Assignees
Labels
bug Something isn't working compiler frontend `noirc_frontend` crate good first issue Good for newcomers

Comments

@shuklaayush
Copy link
Contributor

Aim

I was trying to use the Self keyword as a path to call the static one() method in noir

struct S { }

impl S {
    fn one() -> Field {
        1
    }

    fn two() -> Field {
        Self::one() + Self::one()
        // This compiles
        // S::one() + S::one()
    }
}

fn main() { }

Expected Behavior

Self keyword should be resolved in the path, allowing for the method to be called, just as it would be in Rust.

Bug

When attempting to use the Self keyword in noir, the following error is thrown:

error: Could not resolve 'Self' in path.

To Reproduce

  1. Copy the code above
  2. Run nargo compile --allow-warnings

Installation Method

Compiled from source

Nargo Version

nargo 0.6.0 (git version hash: 0181813, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@shuklaayush shuklaayush added the bug Something isn't working label Jun 22, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jun 22, 2023
@jfecher jfecher added the compiler frontend `noirc_frontend` crate label Jul 21, 2023
@kevaundray
Copy link
Contributor

"We need an explicit check for Self" - @jfecher

@kevaundray
Copy link
Contributor

@jfecher is this still an issue?

@kevaundray kevaundray added the good first issue Good for newcomers label Jan 15, 2024
@michaeljklein
Copy link
Contributor

Just ran into this:

struct Foo { }

impl Foo {
    fn foo() { }

    fn bar() {
        Self::foo()
    }
}

github-merge-queue bot pushed a commit that referenced this issue Jul 31, 2024
# Description

## Problem

Resolves #1791

## Summary

When resolving a path (any path), we now check if the first segment is
`Self` (a similar check is done in another places of our codebase). If
so, resolve the next path segments relative to that type. Only struct
types are supported here... in theory a trait type can also show up, but
that case is handled as a special case in the compiler. I'll create a
follow-up PR removing that special case and seeing if it works.

## Additional Context

None.

## 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 Jul 31, 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 compiler frontend `noirc_frontend` crate good first issue Good for newcomers
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

5 participants