noir icon indicating copy to clipboard operation
noir copied to clipboard

Can't use trait with a where clause referring to a trait with associated types with bounds

Open asterite opened this issue 11 months ago • 2 comments

Aim

As a follow-up to #8594, this code:

trait Foo {
    type E: Bar;
    fn bar(self) -> Self::E;
}

trait Bar {
    fn bar_method(self);
}

trait Baz<T>
where
    T: Foo,
{
    fn baz(t: T) {
        let bar = t.bar();
        bar.bar_method(); // This method here is not found
    }
}

Expected Behavior

Should compile.

Bug

It doesn't compile.

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

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 avatar May 21 '25 15:05 asterite

@asterite ~I don't see any impl for Bar here.~ Ah, I missed the trait constraint on the associated type.

TomAFrench avatar May 21 '25 16:05 TomAFrench

This looks like it'd be a bit tricky to implement. I think the simplest way would be rewriting

trait Baz<T>
where
    T: Foo,
{

as

trait Baz<T>
where
    T: Foo, <T as Foo>::E: Bar
{

Or similar. Alternatively we could go the opposite way and try to propagate the E: Bar constraint up within baz as an assumed constraint but it seems like that will end up with more manual checks and places to forget.

jfecher avatar Jun 26 '25 18:06 jfecher