summaryrefslogtreecommitdiff
path: root/Test/dafny0/ReturnErrors.dfy
blob: da6687158be09fab4fdd71bda5f53d50726a1fbe (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
39
40
41
42
43
44
// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

class N
{
   var i: int;
   method newN(n: N)
      requires n != null;
      modifies this, n;
   {
      n.i := 1;
      i := 1;
   }
   method safe(n: N)
      requires n != null;
      modifies this;
   {
      i := n.i;
   }
}

method m(v: int, n: N) returns (r: int)
   modifies n;
   ensures r == v;
{
   r := v;
}
method testing1() returns (s: int)
   ensures s == 3;
{
   var n := new N;
   return m(3, n); // ERROR: methods disallowed.
}
method testing2() returns (s: int, b: int)
   ensures s == 3;
{
   var n := new N;
   return m(3, n), 2; // ERROR: methods disallowed.
}

method testing3() returns (n: N)
{
   return new N.newN(n); // ERROR: disallowed, as newN() modifies n
}