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

Trait implemented for all T is not resolved #3940

Closed
Tracked by #2568
sirasistant opened this issue Jan 3, 2024 · 0 comments · Fixed by #4013
Closed
Tracked by #2568

Trait implemented for all T is not resolved #3940

sirasistant opened this issue Jan 3, 2024 · 0 comments · Fixed by #4013
Assignees
Labels
bug Something isn't working

Comments

@sirasistant
Copy link
Contributor

Aim

Implementing a trait for types that implements two other traits:

use dep::std::ops::Eq;
use dep::std::default::Default;

trait IsDefault {
    fn is_default(self) -> bool;
}

impl<T> IsDefault for T where T: Default + Eq {
    fn is_default(self) -> bool {
        self.eq(T::default())
    }
}

struct Foo {
    a: u64,
}

impl Eq for Foo {
    fn eq(self, other: Foo) -> bool { self.a == other.a } 
}

impl Default for Foo {
    fn default() -> Self {
        Foo { a: Default::default() }
    }
}

fn main(a: Foo) -> pub bool {
    a.is_default()
}

Expected Behavior

Should compile!

Bug

fails with

No method named 'is_default' found for type 'Foo'

To Reproduce

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@sirasistant sirasistant added the bug Something isn't working label Jan 3, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jan 3, 2024
@jfecher jfecher self-assigned this Jan 3, 2024
@Savio-Sou Savio-Sou mentioned this issue Jan 5, 2024
46 tasks
github-merge-queue bot pushed a commit that referenced this issue Jan 15, 2024
#4013)

Resolved: #3940

Functionality was already there, but a `?` operator was short circuiting
the resolution if the known type didn't have the implemented methods,
avoiding looking for the generic implementations.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Jan 15, 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.

3 participants