forked from dafny-lang/dafny
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit-issue-1172.dfy
More file actions
189 lines (159 loc) · 4.83 KB
/
Copy pathgit-issue-1172.dfy
File metadata and controls
189 lines (159 loc) · 4.83 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
// RUN: %exits-with 2 %run "%s" > "%t"
// RUN: %diff "%s.expect" "%t"
// The following examples show that verification would be unsound if ghost methods would
// be allowed to avoid termination checking.
ghost function F(): int
ensures false
decreases * // error: this is not allowed on a function
{
F()
}
function G(): int
ensures false
decreases * // error: this is not allowed on a function
{
G()
}
twostate predicate P2()
ensures false
decreases * // error: this is not allowed on a function
{
P2()
}
ghost method GM()
ensures false
decreases * // error: this is not allowed on a ghost method
{
GM();
}
lemma Lemma()
ensures false
decreases * // error: this is not allowed on a lemma
{
Lemma();
}
twostate lemma L2()
ensures false
decreases * // error: this is not allowed on a lemma
{
L2();
}
least lemma Least()
ensures false // even without the "decreases *", this postcondition would not get passed the verifier
decreases * // error: this is not allowed on a lemma
{
Least#[_k]();
}
method Main()
decreases *
{
if {
case true =>
var x := F();
case true =>
var x := G();
case true =>
var p := P2();
case true =>
GM();
case true =>
Lemma();
case true =>
L2();
case true =>
Least();
}
var x := 1 / 0; // no error, because all postconditions of the called methods/functions imply "false"
}
// ---------------------- other decreases related errors ----------------------
least predicate Min(x: int)
decreases x // error: decreases not allowed on extreme predicates
{
true
}
greatest predicate Max(x: int)
decreases x // error: decreases not allowed on extreme predicates
{
true
}
least lemma MinLemma(x: int)
decreases x // fine
{
if 0 < x {
MinLemma(x - 1);
}
}
greatest lemma MaxLemma(x: int)
decreases x // fine
{
if 0 < x {
MaxLemma(x - 1);
}
}
// ---------------------- duplicate *'s ----------------------
method Recursive0(x: int, y: int)
decreases x, y, * // error: * can only be mentioned alone in a decreases clause
method Recursive1(x: int, y: int)
decreases *, x, y // error: * can only be mentioned alone in a decreases clause
method Recursive2(x: int, y: int)
decreases x, y
decreases * // error: * can only be mentioned alone in a decreases clause
method Recursive3(x: int, y: int)
decreases *
decreases x, y // error: * can only be mentioned alone in a decreases clause
method Recursive4(x: int, y: int)
decreases x, *, y // error: * can only be mentioned alone in a decreases clause
method Recursive5(x: int, y: int)
decreases x, *, y, * // error: * can only be mentioned alone in a decreases clause
method Recursive6(x: int, y: int)
decreases *
decreases x // error: * can only be mentioned alone in a decreases clause
decreases * // error: * can only be mentioned alone in a decreases clause
decreases y // error: * can only be mentioned alone in a decreases clause
decreases * // error: * can only be mentioned alone in a decreases clause
method Loops(M: int, N: int, O: int, P: int) {
var i, j, k, l := M, N, O, P;
while i != 0
decreases i, * // error: * can only be mentioned alone in a decreases clause
{
i := i - 1;
}
while j != 0
decreases *, j // error: * can only be mentioned alone in a decreases clause
{
j := j - 1;
}
while k != 0
decreases k
decreases * // error: * can only be mentioned alone in a decreases clause
decreases * // error: * can only be mentioned alone in a decreases clause
{
k := k - 1;
}
while l != 0
decreases *, k // error: * can only be mentioned alone in a decreases clause
decreases l, * // error: * can only be mentioned alone in a decreases clause
{
l := l - 1;
}
}
ghost function Function0(x: object, y: object): int
reads x, y, * // error: * can only be mentioned alone in a reads clause
ghost function Function1(x: object, y: object): int
reads *, x, y // error: * can only be mentioned alone in a reads clause
ghost function Function2(x: object, y: object): int
reads x, y
reads * // error: * can only be mentioned alone in a reads clause
ghost function Function3(x: object, y: object): int
reads *
reads x, y // error: * can only be mentioned alone in a reads clause
ghost function Function4(x: object, y: object): int
reads x, *, y // error: * can only be mentioned alone in a reads clause
ghost function Function5(x: object, y: object): int
reads x, *, y, * // error: * can only be mentioned alone in a reads clause
ghost function Function6(x: object, y: object): int
reads *
reads x // error: * can only be mentioned alone in a reads clause
reads * // error: * can only be mentioned alone in a reads clause
reads y // error: * can only be mentioned alone in a reads clause
reads * // error: * can only be mentioned alone in a reads clause