I have trouble understanding some behaviour of Viper, which, imho, seems to be a bug.
The following code fails to verify due to a lack of permissions for bar.val_int
on the assignment. This makes total sense.
field val_int: Int
method foo() {
var bar: Ref
inhale acc(bar.val_int)
exhale acc(bar.val_int)
bar.val_int := 2
}
Yet, the following code verifies successfully:
field val_int: Int
method foo() {
var bar: Ref
inhale acc(bar.val_int)
inhale acc(bar.val_int)
exhale acc(bar.val_int)
exhale acc(bar.val_int)
bar.val_int := 2
}
As a matter of fact, one can add an arbitrary number of exhales, as long as there are two inhales (for full permissions) at the top, the code will always verify. Is this a bug, intentional, or am I missing something weird that is happening?
I would have expected the second inhale to have no effect, as a full permission is already held for the heap location. However, even if somehow a double write permission is help (which should be illegal?), then at least I would expect the two exhale
statements to revoke these permissions, leaving again no permissions at the moment of assignment.