Closed
Description
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.