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

method lookup within an impl fails when receiver is an iface type variable #1909

Closed
nikomatsakis opened this issue Feb 27, 2012 · 0 comments
Closed
Labels
A-type-system Area: Type system

Comments

@nikomatsakis
Copy link
Contributor

the following will not compile:

iface foo {
    fn one() -> uint;
}

impl of foo for uint {
    fn one() -> uint { ret self; }
}

impl extra<F: foo> for F {
    fn two() -> uint { ret self.one() * 2u; }

    fn four() -> uint { ret self.two() * 2u; }
    // ^ Error: method two() not found
}

fn main() {
    let x = 1u.one();
    let x = 1u.two();
    let x = 1u.four();
}

I assume the problem is that the method lookup says "ah, self is a type variable that implements foo" and thus just searches the iface foo for the method two(). This is of course correct, but it should also search for in-scope impls.

In the absence of traits, defining impls like this is a handy way to get "default" method implementations. I put "default" in quotes because they can't be overridden. Regardless it should work---it's still useful to be able to "extend" an iface like this. I wanted it for my mockups of the iter library.

I assigned @marijnh since he seems best qualified.

@ghost ghost assigned marijnh Feb 27, 2012
RalfJung added a commit to RalfJung/rust that referenced this issue Oct 22, 2022
RalfJung pushed a commit to RalfJung/rust that referenced this issue Oct 22, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system
Projects
None yet
Development

No branches or pull requests

2 participants