Dafny: Updating an array of objects #5104
Replies: 2 comments 1 reply
-
It looks like what you are trying to modify are the elements of the array themselves, not the array itself.
And you can now omit Note that if you omit The final answer to that is to ensure that all the elements you added were not allocated at the beginning of the method, so it's perfectly valid to modify them. It has to be captured in an invariant, which looks like this:
Explanation: |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot. That was really helpful. But I want to understand it in more depth. Here's a similar situation:
If I omit the ensure condition, |
Beta Was this translation helpful? Give feedback.
-
The method
update_arr
tries to update the fieldx
of an array of objects ofclass A
. If I want to update the i-th element of the array in place bya.arr[i].update_x(10)
, the verifier gives error. But if I create a copy of the object and then update the value ofx
, then it is verified. What can I do to get it verified without creating any copies?Beta Was this translation helpful? Give feedback.
All reactions