mozilla/rust — Issue #1909: method lookup within an impl fails when receiver is an iface type variable
Author: nikomatsakis
Created: 2012-02-27 02:21:02+00:00
State: open
Labels: A-typesystem

the following will not compile:

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

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

impl extra 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.