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

Traits with associated types can't be used in where clauses #6571

Open
michaeljklein opened this issue Nov 21, 2024 · 2 comments · May be fixed by #7026
Open

Traits with associated types can't be used in where clauses #6571

michaeljklein opened this issue Nov 21, 2024 · 2 comments · May be fixed by #7026
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Given a simple trait with an associated type:

trait Foo {
    type Bar;
}

I attempted to require Foo in a where clause in three ways:

// using "where (): Foo" fails with the same error,
// even if the following impl is present:
// impl Foo for () {
//     type Bar = ();
// }
impl<T> Foo for Option<T> where T: Foo {
    type Bar = T;
}
trait Baz { }

impl<T> Baz for Option<T> where T: Foo { }
fn foo<T>(x: T) where T: Foo { }

Expected Behavior

Expected the above cases to compile successfully

Bug

Each fails with 'Foo' is missing the associated type 'Bar':

error: `Foo` is missing the associated type `Bar`
  ┌─ src/main.nr:5:36
  │
5 │ impl<T> Foo for Option<T> where T: Foo {
  │                                    ---
  │
error: `Foo` is missing the associated type `Bar`
  ┌─ src/main.nr:7:36
  │
7 │ impl<T> Baz for Option<T> where T: Foo { }
  │                                    ---
  │
error: `Foo` is missing the associated type `Bar`
  ┌─ src/main.nr:5:27
  │
5 │ fn foo<T>(x: T) where (): Foo { }
  │                           ---
  │

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.39.0 noirc version = 0.39.0+68c32b4ffd9b069fe4b119327dbf4018c17ab9d4 (git version hash: 68c32b4, 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 21, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Nov 21, 2024
@jfecher
Copy link
Contributor

jfecher commented Jan 6, 2025

This is expected currently while the feature is incomplete - the only thing we've shipped so far is an explicit version where associated types must always be specified. So I'd expect the following to work:

fn foo<T, U>(x: T) where T: Foo<Bar = U> { }

(we should keep this issue until associated types are feature complete though)

@michaeljklein
Copy link
Contributor Author

Ok: just confirmed that an explicit associated type in the where clause works 👍

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