My guess as to what's happening is that Dafny thinks M2 might update x.inner.val to point to a different Ref<int> that isn't covered by M1's modifies, so the call to M3 may violate M1's frame condition. But that's impossible because M2 can't modify anything.
Adding SameOrNewRefs to M2's postcondition convinces Dafny that the reference is either unchanged or newly allocated and the error goes away. However, I'd expect it to be able to figure that out without any hints. The issue seems also to be related to the depth of the nested references. Removing one level of Ref in inner's type, or replacing X with type X = Ref<Ref<int>> also fixes the error without the need for SameOrNewRefs.
What type of operating system are you experiencing the problem on?
Dafny version
4.2.0
Code to produce this issue
Command to run and resulting output
What happened?
My guess as to what's happening is that Dafny thinks
M2
might updatex.inner.val
to point to a differentRef<int>
that isn't covered byM1
's modifies, so the call toM3
may violateM1
's frame condition. But that's impossible becauseM2
can't modify anything.Adding
SameOrNewRefs
toM2
's postcondition convinces Dafny that the reference is either unchanged or newly allocated and the error goes away. However, I'd expect it to be able to figure that out without any hints. The issue seems also to be related to the depth of the nested references. Removing one level ofRef
ininner
's type, or replacingX
withtype X = Ref<Ref<int>>
also fixes the error without the need forSameOrNewRefs
.What type of operating system are you experiencing the problem on?
Mac