about summary refs log tree commit diff
path: root/src/test/run-pass/stateful-obj.rs
blob: 97160244d16d113f7b70bf784121048b56284401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19



// -*- rust -*-
obj counter(mutable x: int) {
    fn hello() -> int { ret 12345; }
    fn incr() { x = x + 1; }
    fn get() -> int { ret x; }
}

fn main() {
    let y = counter(0);
    assert (y.hello() == 12345);
    log y.get();
    y.incr();
    y.incr();
    log y.get();
    assert (y.get() == 2);
}