【发布时间】:2019-12-18 18:28:54
【问题描述】:
假设我有以下课程:
class Testing {
ghost var myGhostVar: int;
method Init()
modifies this
ensures this.myGhostVar == -1
{
this.myGhostVar := -1;
assert this.myGhostVar == -1;
}
method MyTestingMethod(list: array<int>, t: int)
modifies this
requires list.Length > 1
requires this.myGhostVar == -1
requires t == -1
ensures MyPredicate(list, myGhostVar)
ensures this.myGhostVar < list.Length
{
this.Init();
assert this.myGhostVar < 0;
assert list.Length > 0;
assert this.myGhostVar < list.Length;
}
predicate MyPredicate(list: array<int>, startIndex: int)
requires startIndex < list.Length
{
true
}
}
出于某种原因,Dafny 说对MyPredicate(...) 的呼叫可能无法保持。但如果我改为使用t 而不是myGhostVar 作为参数;达芙妮没有任何抱怨。
两者都有相同的requires 谓词,这使得这一切都有些混乱。是不是我在使用 ghost 变量时遗漏了什么?
【问题讨论】:
标签: dafny