summaryrefslogtreecommitdiff
path: root/Test/hofs/Naked.dfy
blob: d23eb507ce3cfc4e6a50cc20bb75c754210fa5f0 (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
// RUN: %dafny "%s" > "%t"
// RUN: %diff "%s.expect" "%t"

module Functions {
  function f(x: nat): nat
  {
    if x == 0 then 0 else
    if var b: bool :| true; b then
      var h := f;
      h(x-1)
    else
      (f)(x-1)
  }

  function f1(x: nat): nat { if x == 0 then 0 else f2(x - 1) }

  function f2(x: nat): nat { if x == 0 then 0 else (f1)(x - 1) }
}

module Requires {
  function t(x: nat): nat
  requires !t.requires(x);  // error: use of naked function in its own SCC
  { x }

  function g(x: nat): nat
  requires !(g).requires(x);  // error: use of naked function in its own SCC
  { x }

  function D(x: int): int  // used so termination errors don't mask other errors
  function g2(x: int): int decreases D(x) { h(x) }  // error: precondition violation
  function h(x: int): int
    requires !g2.requires(x);  // error: use of naked function in its own SCC
  { x }
}

module Reads {
  function t(x: nat): nat
  reads t.reads(x);
  { x }

  function g(x: nat): nat
  reads (g).reads(x);
  { x }

  function g2(x: int): int { h(x) }

  function h(x: int): int
    reads g2.reads(x);
  { x }
}