Closed
Description
Apparently it is enough to write an anonymous implementation with the correct function name and signature to get the compiler to spit out operator overloading:
struct Thing {
x: int
}
// Look ma, no Mul!
impl Thing/*: Mul<int, Thing>*/ {
pure fn mul(c: &int) -> Thing {
Thing {x: self.x * *c}
}
}
fn main() {
let u = Thing {x: 2};
let _v = u.mul(&3); // Works
let w = u * 3; // Works!!
io::println(fmt!("%i", w.x));
/*
// This doesn't work though.
let u2 = u as @Mul<int, Thing>;
let w2 = u2.mul(&4);
io::println(fmt!("%i", w2.x));
*/
}
This is probably not intended? And it leads to nasty ICEs when the function name fits, but the function signature doesn't (eg. pure fn mul(c: int) -> Thing
, no reference).