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

Errors when importing traits #6479

Closed
nventuro opened this issue Nov 7, 2024 · 0 comments · Fixed by #6506
Closed

Errors when importing traits #6479

nventuro opened this issue Nov 7, 2024 · 0 comments · Fixed by #6506
Assignees
Labels
bug Something isn't working

Comments

@nventuro
Copy link
Contributor

nventuro commented Nov 7, 2024

Aim

I noticed some incorrect 'unused import' warnings, and after looking into it some more found some strange incorrect behavior when importing traits. It may extend to other imports.

Bug

The following program seems correct:

mod foo {
    pub trait Foo<let N: u32> {
    }
}

use foo::Foo;

pub trait Bar<T, let N: u32> where T: Foo<N> {}

fn main() {
}

but it compiles with a seemingly incorrect warning:

warning: unused import Foo
  ┌─ src/main.nr:6:10
  │
6 │ use foo::Foo;
  │          --- unused import

since Foo is clearly used in Bar's declaration.

Removing the use::foo:Foo line does not cause a compilation error, which I also found odd.


Curiously, adding a second trait causes for the warning to go away:

mod foo {
    pub trait Bar<let N: u32> {
    }
}

use foo::Bar;

trait Qux {}

pub trait Baz<T, let N: u32> where T: Bar<N> {}

fn main() {
}

but this depends on the order of the declarations - the following program does emit the original warning:

mod foo {
    pub trait Bar<let N: u32> {
    }
}

use foo::Bar;

pub trait Baz<T, let N: u32> where T: Bar<N> {}

trait Qux {}

fn main() {
}

Finally, placing the new trait inside a new module causes a compilation error instead:

mod foo {
    pub trait Bar<let N: u32> {
    }
}

use foo::Bar;

pub trait Baz<T, let N: u32> where T: Bar<N> {}

mod qux { 
    trait Qux {}
}

fn main() {
}
warning: unused import Bar
  ┌─ src/main.nr:6:10
  │
6 │ use foo::Bar;
  │          --- unused import
  │

error: Could not resolve 'Bar' in path
  ┌─ src/main.nr:8:39
  │
8 │ pub trait Baz<T, let N: u32> where T: Bar<N> {}
  │                                       ---
  │
@nventuro nventuro added the bug Something isn't working label Nov 7, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 7, 2024
@asterite asterite self-assigned this Nov 12, 2024
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Nov 12, 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.

2 participants