summaryrefslogtreecommitdiff
path: root/Test/dafny0/Backticks.dfy
blob: 08606b559ad123187b34f33ef8999d447a524cd7 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// RUN: %dafny /compile:0 /print:"%t.print" /dprint:"%t.dprint" "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

class C {
  var x: int
  var y: int
  ghost var z: int

  function F(): int
    reads `x
  {
    x
  }

  function G(): int
    reads `x
  {
    F()
  }

  function H(): int
    reads this
  {
    F()
  }

  function I(n: nat): int
    reads this
  {
    x + y + z + J(n)
  }

  function J(n: nat): int
    reads `x, this`z
    decreases {this}, n, 0
  {
    if n == 0 then 5 else
    I(n-1)  // error: insufficient reads clause
  }

  function K(n: nat): int
    reads `x
    decreases {this}, n+1
  {
    L(n)
  }

  function L(n: nat): int
    reads `x
  {
    if n < 2 then 5 else K(n-2)
  }

  method M()
    modifies `x
  {
    N();
  }

  method N()
    modifies `x
  {
    x := x + 1;
  }

  method O(n: nat)
    modifies this
  {
    P(n);
  }
  method P(n: nat)
    modifies `x
    decreases n, 0
  {
    x := x + 1;
    if n != 0 {
      O(n-1);  // error: insufficient modifies clause to make call
    }
  }
}