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

FunctionDefinition::as_typed_expr fails when the trait impl has a where clause #7610

Closed
asterite opened this issue Mar 6, 2025 · 0 comments · Fixed by #7611
Closed

FunctionDefinition::as_typed_expr fails when the trait impl has a where clause #7610

asterite opened this issue Mar 6, 2025 · 0 comments · Fixed by #7611
Assignees
Labels
bug Something isn't working

Comments

@asterite
Copy link
Collaborator

asterite commented Mar 6, 2025

Aim

This code:

trait Trait {}

impl Trait for i32 {}

trait Packable<let N: u32> {
    fn pack(self);
}

struct Foo<T> {}

impl<T> Packable<10> for Foo<T>
where
    T: Trait,
{
    fn pack(self) {}
}

fn main() {
    comptime {
        let foo = quote { Foo<i32> }.as_type();
        let t = quote { Packable<10> }.as_trait_constraint();
        let method = foo.get_trait_impl(t).unwrap().methods().filter(|method| {
            method.name() == quote { pack }
        })[0]
            .as_typed_expr();
    }
}

Expected Behavior

It should compile.

Bug

It fails with this error:

error: Object type is unknown in method call
   ┌─ src/main.nr:23:22
   │
23 │             let method = foo.get_trait_impl(t).unwrap().methods().filter(|method| {
   │ ╭────────────────────────'
   │ │ ╭──────────────────────'
24 │ │ │             method.name() == quote { pack }
25 │ │ │         })[0]
26 │ │ │             .as_typed_expr();
   │ ╰─│────────────────────────────' Type must be known by this point to know which method to call
   │   ╰────────────────────────────' While evaluating `FunctionDefinition::as_typed_expr

The compiler is trying to solve T: Trait in the trait impl and fails, but T at that point is an unbound type variable.

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

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.

1 participant