rust/src/test/run-pass/anon-obj-with-self-call.rs

31 lines
527 B
Rust
Raw Normal View History

use std;
fn main() {
obj a() {
2011-07-27 14:19:39 +02:00
fn foo() -> int { ret 2; }
fn bar() -> int { ret self.foo(); }
}
2011-07-27 14:19:39 +02:00
let my_a = a();
2011-07-27 14:19:39 +02:00
let my_b =
obj () {
fn baz() -> int { ret self.foo(); }
with
my_a
};
2011-06-23 10:47:29 -07:00
assert (my_b.baz() == 2);
2011-07-27 14:19:39 +02:00
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);
2011-07-27 14:19:39 +02:00
}