rust/src/test/run-pass/anon-obj-with-self-call.rs
2011-07-27 15:54:33 +02:00

31 lines
527 B
Rust

use std;
fn main() {
obj a() {
fn foo() -> int { ret 2; }
fn bar() -> int { ret self.foo(); }
}
let my_a = a();
let my_b =
obj () {
fn baz() -> int { ret self.foo(); }
with
my_a
};
assert (my_b.baz() == 2);
let my_c =
obj () {
fn foo() -> int { ret 3; }
fn baz() -> int { ret self.foo(); }
with
my_a
};
assert (my_c.baz() == 3);
assert (my_c.bar() == 3);
}