-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Closed
Description
% rustc --version
rustc 0.6 (77ee858 2013-02-02 11:54:29 +0100)
host: x86_64-apple-darwin
% cat bug4.rs
pub trait OpInt { fn call(&self, int, int) -> int; }
pub trait OpFlo { fn call(&self, float, float) -> float; }
pub trait Op<T> { fn call(&self, T,T) -> T; }
impl fn(int,int) -> int : OpInt {
fn call(&self, a:int, b:int) -> int { (*self)(a,b) }
}
impl fn(float,float) -> float : OpFlo {
fn call(&self, a:float, b:float) -> float { (*self)(a,b) }
}
impl<T> fn(T,T) -> T : Op<T> {
fn call(&self, a:T, b:T) -> T { (*self)(a,b) }
}
fn squarei(x:int, op:&OpInt) -> int { op.call(x, x) }
fn squaref(x:float, op:&OpFlo) -> float { op.call(x, x) }
fn squareg<T : Copy>(x:T, op:&Op<T>) -> T { op.call(x, x) }
fn muli(x:int, y:int) -> int { x * y }
fn mulf(x:float, y:float) -> float { x * y }
fn echo<T>(x:T) { io::println(fmt!("%?", x)); }
fn main() {
let r = squarei(3, (|x,y|muli(x,y)) as &OpInt); echo(r);
let s = squaref(3f, (|x,y|mulf(x,y)) as &OpFlo); echo(s);
// This seems analagous to cases above, but parser fails on it.
let t = squareg(3, &muli as &Op::<int>); echo(t);
}
% rustc bug4.rs
bug4.rs:31:35: 31:37 error: expected `,` but found `::`
bug4.rs:31 let t = squareg(3, &muli as &Op::<int>); echo(t);
^~
Metadata
Metadata
Assignees
Labels
No labels