2011-06-16 19:33:31 -05:00
|
|
|
use std;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
|
|
|
obj a() {
|
2011-07-27 07:19:39 -05:00
|
|
|
fn foo() -> int { ret 2; }
|
|
|
|
fn bar() -> int { ret self.foo(); }
|
2011-06-16 19:33:31 -05:00
|
|
|
}
|
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let my_a = a();
|
2011-06-16 19:33:31 -05:00
|
|
|
|
2011-07-07 19:10:17 -05:00
|
|
|
// An anonymous object that overloads the 'foo' method.
|
2011-07-27 07:48:34 -05:00
|
|
|
let my_b =
|
2011-07-27 07:19:39 -05:00
|
|
|
obj () {
|
|
|
|
fn foo() -> int { ret 3; }
|
|
|
|
with
|
|
|
|
my_a
|
|
|
|
};
|
2011-06-16 19:33:31 -05:00
|
|
|
|
|
|
|
assert (my_b.foo() == 3);
|
|
|
|
assert (my_b.bar() == 3);
|
2011-07-20 17:46:56 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let my_c =
|
|
|
|
obj () {
|
|
|
|
fn baz(x: int, y: int) -> int { ret x + y + self.foo(); }
|
|
|
|
with
|
|
|
|
my_b
|
|
|
|
};
|
2011-07-20 17:46:56 -05:00
|
|
|
|
2011-07-27 07:19:39 -05:00
|
|
|
let my_d =
|
|
|
|
obj () {
|
|
|
|
fn baz(x: int, y: int) -> int { ret x + y + self.foo(); }
|
|
|
|
with
|
|
|
|
my_a
|
|
|
|
};
|
2011-07-20 17:46:56 -05:00
|
|
|
|
|
|
|
assert (my_c.baz(1, 2) == 6);
|
|
|
|
assert (my_d.baz(1, 2) == 5);
|
2011-07-27 07:19:39 -05:00
|
|
|
}
|