Skip to content

call might violate context's modifies clause #2164

Answered by keyboardDrummer
dreamqin68 asked this question in Q&A
Discussion options

You must be logged in to vote

You can resolve your issue by assigning a value to a before passing it to test, like so:

method test(element:int, a:array<int>)
   requires a.Length > 2
   modifies a;
{
   a[0] := element;
}

method Main()
{
   var a : array<int> := new int[] [1,2,3];
   var element : int;
   assume a.Length > 2;
   test(element, a);
}

I guess you should view this as: you cannot call a method that modifies an unassigned value. I think your original program would crash if executed because it writes to an unassigned array. I will create an issue in Dafny because I do find that the error message is not clear about what the problem is. (#2171)

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@dreamqin68
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
2 participants