summaryrefslogtreecommitdiff
path: root/tiger-compiler/tests/object/good/override.tig
blob: 550d3cd4ed5347eb981e2a26f0b65e1dcd2464a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
let
  class C
  {
    var a := 0
    method m() : int = self.a
  }
  class D extends C
  {
    var b := 9
    /* Override C.m().  */
    method m() : int = self.a + self.b
  }
  var d : D := new D
  /* Valid upcast due to inclusion polymorphism.  */
  var c : C := d
  in
    c.a := 42;
    /* Note that accessing `c.b' is not allowed, since `c' is
         statically known as a `C', even though it is actually a `D'
         at run time.  */
    let
      /* Polymorphic call.  */
    var res := c.m()
    in
      print_int(res);
      print("\n")
    end
end