summaryrefslogtreecommitdiff
path: root/Test/dafny0/TypeTests.dfy
blob: fe8644befcbbf90fddb2f45b537f94fedb00c537 (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
class C {
  function F(c: C, d: D): bool { true }
  method M(x: int) returns (y: int, c: C)
    requires F(#D.A, this);  // 2 errors
    requires F(4, 5);  // 2 errors
    requires F(this, #D.A);  // good
  { }

  method Caller()
  {
    call m,n := M(true);  // error on in-parameter
    call n,m := M(m);  // 2 errors on out-parameters
  }
}

datatype D {
  A;
}

datatype Nothing {  // error: no grounding constructor
}

datatype NeverendingList {  // error: no grounding constructor
  Cons(int, NeverendingList);
}

datatype MutuallyRecursiveDataType<T> {
  FromANumber(int);  // this is the base case
  Else(TheCounterpart<T>, C);
}

datatype TheCounterpart<T> {
  TreeLike(TheCounterpart<T>, TheCounterpart<T>);
  More(MutuallyRecursiveDataType<T>);
}

// these 'ReverseOrder_' order tests may be called white-box unit tests
datatype ReverseOrder_MutuallyRecursiveDataType<T> {
  FromANumber(int);  // this is the base case
  Else(ReverseOrder_TheCounterpart<T>, C);
}

datatype ReverseOrder_TheCounterpart<T> {
  TreeLike(ReverseOrder_TheCounterpart<T>, ReverseOrder_TheCounterpart<T>);
  More(ReverseOrder_MutuallyRecursiveDataType<T>);
}

// ---------------------

class ArrayTests {
  ghost method G(a: array<int>)
    requires a != null && 10 <= |a|;
    modifies a;
  {
    a[7] := 13;  // error: array elements are not ghost locations
  }
}