noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
905 stars 206 forks source link

Where clause on generic trait's generic argument fails to resolve #6467

Open michaeljklein opened 2 weeks ago

michaeljklein commented 2 weeks ago

Aim

Attempted to compile a program where a trait constrains one of its generic arguments:

trait Foo {
    fn foo(self) -> bool;
}

trait Bar<T> where T: Foo {}

impl<T, U> Bar<T> for U where T: Foo {}

pub fn bar<T, U>(x: T, _: U) -> bool where U: Bar<T> {
    x.foo()
}

fn main() {}

Note: this is blocking trait aliases of the form:

trait Qux<T> = Foo + Bar<T> where T: Baz;
//                          ^ this where clause results in the same "unresolved method call" error

Expected Behavior

Expected the x.foo() call to resolve since x: T and U: Bar<T> implies T: Foo

Bug

The method call does not resolve:

❯ ~/.nargo/bin/nargo compile
error: No method named 'foo' found for type 'T'
   ┌─ src/main.nr:10:5
   │
10 │     x.foo()
   │     -------
   │

Aborting due to 1 previous error

To Reproduce

1. 2. 3. 4.

Workaround

None

Workaround Description

No response

Additional Context

Note: need to update the docs that reference this issue

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.37.0 noirc version = 0.37.0+fb1a8ca67c58d87991358078e6c532b49824fdb8 (git version hash: fb1a8ca67c58d87991358078e6c532b49824fdb8, 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

asterite commented 2 weeks ago

Expected the x.foo() call to resolve since x: T and U: Bar implies T: Foo

I'm not sure if this explicitness is expected from the language... Or, well, at least in Rust I get an error that says "the trait bound T: Foo is not satisfied, the trait Foo is not implemented for T" on Bar<T>.