blob: 512c65c18f93e8489afcbc319e5c1c4b944c0267 (
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 Node {
var value: int;
method init(v: int)
requires acc(value)
ensures valid
{
value := v
fold this.valid
}
function get():int requires valid { unfolding valid in value }
method set(v: int)
requires valid
ensures valid && get() == v
{
unfold valid
value := v
fold valid
}
predicate valid {
acc(value)
}
method main(x: Node, y: Node)
requires x != null && y != null
requires x.valid && y.valid
{
call x.set(3)
call y.set(3)
call x.set(3)
call y.set(3)
call x.set(3)
call y.set(3)
call x.set(3)
unfold x.valid
x.value := 3
fold x.valid
call y.set(3)
call x.set(3)
call y.set(3)
unfold x.valid
x.value := 3
fold x.valid
unfold x.valid
x.value := 3
fold x.valid
call x.set(3)
call y.set(3)
call x.set(4)
assert y.get() == 3
assert x.get() == 3 // error: should fail
}
}
|