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

Invalid paths in default trait method only error when trait is implemented #6519

Open
michaeljklein opened this issue Nov 14, 2024 · 0 comments · May be fixed by #6645
Open

Invalid paths in default trait method only error when trait is implemented #6519

michaeljklein opened this issue Nov 14, 2024 · 0 comments · May be fixed by #6645
Assignees
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to debug a Noir program by adding invalid variables to the body of a default method:

trait Foo {
    pub fn foo(self, x: Field) {
        InvalidTypeName::invalid_method_name();
        x.other_invalid_method_name();
        invalid_function_name();
        let _: [InvalidTypeName; InvalidGeneric] = self.invalid_self_method_name();
        invalid_variable_name
    }

    // The expected error occurs when either a parameter or the return type is unknown:
    // error: Could not resolve 'InvalidTypeName' in path
    // pub fn bar(self) -> InvalidTypeName { }
    // pub fn bar(self, x: InvalidTypeName) { }
}

// The expected error occurs when implementing 'Foo':
// error: Could not resolve 'invalid_method_name' in path
// impl Foo for () {}

fn main() { }

Expected Behavior

Expected error: Could not resolve 'invalid_method_name' in path and/or similar errors for:

  • other_invalid_method_name
  • invalid_function_name
  • InvalidTypeName
  • InvalidGeneric
  • invalid_self_method_name
  • invalid_variable_name

Bug

Invalid paths in default trait methods should error. E.g. for the Rust program:

trait Foo {
    fn foo(&self, x: u64) {
        InvalidTypeName::invalid_method_name();
    }
}

Rust returns the error:

error[E0433]: failed to resolve: use of undeclared type `InvalidTypeName`
 --> src/main.rs:4:9
  |
4 |         InvalidTypeName::invalid_method_name();
  |         ^^^^^^^^^^^^^^^ use of undeclared type `InvalidTypeName`

To Reproduce

Workaround

Yes

Workaround Description

To get the type-checker to run on trait default methods, add an impl for any trait that has default methods, even if its non-default methods are defined to be panic.

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.38.0 noirc version = 0.38.0+0fc0c53ec183890370c69aa4148952b3123cb055 (git version hash: 0fc0c53, is dirty: false)

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

@michaeljklein michaeljklein added the bug Something isn't working label Nov 14, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 14, 2024
@asterite asterite self-assigned this Nov 28, 2024
@asterite asterite linked a pull request Nov 28, 2024 that will close this issue
5 tasks
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

Successfully merging a pull request may close this issue.

2 participants