rust/src/test/run-pass/standalone-method.rs
Marijn Haverbeke 575aae407b Saner approach to lvalues and callable values in trans
LValues no longer carry information about generics and objs, instead
there's an extended form of lvalue, lval_maybe_callee, only used by
call and bind, which holds this info.

This makes it possible to take the value of a method and get a working
closure, and will (with some more work) allow us to call statically
known functions without loading from their pair.

Closes #435
Closes #758
2011-09-16 21:31:36 +02:00

18 lines
398 B
Rust

// Test case for issue #435.
obj foo(x: int) {
fn add5(n: int) -> int { ret n + x; }
}
fn add5(n: int) -> int { ret n + 5; }
fn main() {
let fiveplusseven = bind add5(7);
assert (add5(7) == 12);
assert (fiveplusseven() == 12);
let my_foo = foo(5);
let fiveplusseven_too = bind my_foo.add5(7);
assert (my_foo.add5(7) == 12);
assert (fiveplusseven_too() == 12);
}