Dafny 模块细化编译
编译以下代码时:Dafny 模块细化编译,dafny,Dafny,编译以下代码时: module Interface { function addSome(n: nat): nat ensures addSome(n) > n } module Mod { import A : Interface method m() { assert 6 <= A.addSome(5); print "Test\n"; } } module Implementation refi
module Interface {
function addSome(n: nat): nat
ensures addSome(n) > n
}
module Mod {
import A : Interface
method m() {
assert 6 <= A.addSome(5);
print "Test\n";
}
}
module Implementation refines Interface {
function addSome(n: nat): nat
ensures addSome(n) == n + 1
{
n + 1
}
}
module Mod2 refines Mod {
import A = Implementation
}
method Main() {
Mod2.m();
}
既然
实现
细化了接口
,为什么编译器需要接口。addSome
有一个主体,特别是当addSome
是幻影,所以不应该参与编译时?您需要将接口
和Mod
都标记为抽象
。除此之外,这意味着它们不会被编译,因此您不会得到那个错误
在这两个小更改之后,文件的其余部分将正确编译
Dafny program verifier finished with 5 verified, 0 errors
Compilation error: Function _0_Interface_Compile._default.addSome has no body