Skip to content

Misleading error for missing associated constant accessed directly #11362

@vezenovm

Description

@vezenovm

Aim

Take this test:

#[test]
fn associated_constant_direct_access_no_impl() {
    let src = r#"
    trait MyTrait {
        let N: u32;
    }
    struct Foo {}
    struct Bar {}
    impl MyTrait for Bar {
        let N: u32 = 5;
    }
    fn main() {
        let _ = Bar {};
        let _: u32 = Foo::N;
                          ^ Could not resolve 'N' in path
    }
    "#;
    check_errors(src);
}

Expected Behavior

I would expect an error that tells the user the associated item does not exist. This steers the user towards the expected fix rather than keeping them guessing.

For example in Rust similar code would give the following:

no associated item named `N` found for struct `Foo` in the current scope
items from traits can only be used if the trait is implemented and in scope

It even provides suggestions:

`MyTrait` defines an item `N`, perhaps you need to implement it

Bug

Instead we get Could not resolve 'N' in path.

Before #11361 we would get this error message even for valid associated constants whose trait impls are in scope. However, even once #11361 is in we will want to improve this error message.

To Reproduce

  1. Run the test above in noirc_frontend/tests

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

nargo version = 1.0.0-beta.18 noirc version = 1.0.0-beta.18+f00ead976b22b35a2746c6db06fd77609cabe6ea (git version hash: f00ead9, is dirty: true)

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions