Skip to content

Error with modifies clause #2190

Answered by atomb
dreamqin68 asked this question in Q&A
Jun 1, 2022 · 1 comments · 6 replies
Discussion options

You must be logged in to vote

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);…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@atomb
Comment options

atomb Jun 2, 2022
Maintainer

@dreamqin68
Comment options

@atomb
Comment options

atomb Jun 2, 2022
Maintainer

@dreamqin68
Comment options

@rsingha108
Comment options

Answer selected by dreamqin68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants