Error with modifies clause #2190
Answered
by
atomb
dreamqin68
asked this question in
Q&A
-
Hi All, I have a question and hope to get help. Thanks.
After verification shows This error may be related to |
Beta Was this translation helpful? Give feedback.
Answered by
atomb
Jun 1, 2022
Replies: 1 comment 6 replies
-
This is a very subtle issue! The following modified program passes: class TestType
{
var id:int
}
method test1(element:TestType) returns(b:array<TestType>)
ensures b.Length == 3;
ensures fresh(b)
ensures fresh(b[1])
ensures fresh(b[2])
ensures b[0] == element
{
var a := new TestType;
b:= new TestType[3](_=>a);
b[0] := element;
}
method test2(b:array<TestType>)
requires b.Length == 3
modifies b, b[..]
{
b[0].id := 1; // Allowed because b[0] is equal to element, allocated in main
b[1].id := 1; // Allowed because b[1] is fresh after test1
}
method Main()
{
var element := new TestType;
element.id := 2;
var b:= test1(element);
test2(b); // No error
} Several things are key to point out here:
|
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
dreamqin68
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a very subtle issue! The following modified program passes: