aboutsummaryrefslogtreecommitdiff
path: root/src/test/run-pass/stateful-obj.rs
blob: b0f0cf3b9693c70cdf71e02a0276a968c699ae51 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// -*- rust -*-

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

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