summaryrefslogtreecommitdiff
path: root/Test/dafny0/Trait/Traits-Fields.dfy
blob: 41f596b4f5fe4fc1111433c5b8d31ee31e98ca34 (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
29
30
31
32
33
34
35
36
37
38
// RUN: %dafny /compile:3 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

trait J
{
  var x: int;
}

class C extends J
{

}

method Main() 
{
  var c := new C;
  var j: J := new C;

  j.x := 8;
  c.x := 9;
  assert j.x + 1 == c.x;

  j := c;
  //assert j.x == 9; //why this does not hold??

  print "j"; Print(j);
  print "c"; Print(c);

  c := null;
  assert j != null;
  j := null;
}

method Print(j: J)
  requires j != null;
{
  print ".x = ", j.x, "\n";
}