繁体   English   中英

为什么 Dafny 允许未初始化的返回结果?

[英]Why is Dafny allowing uninitialized return result?

在这种方法中:

datatype Results = Foo | Bar

method test() returns (r:Result)
{
}

Dafny 验证 OK 并且 test() 返回 Foo。 这在技术上是正确的(它确实返回了正确类型的值)但是我期待 Dafny 抱怨结果没有由方法本身设置。 test() 的作用类似于:

return;

在 C function 中,应该返回一个 int。

有没有办法让 Dafny 验证方法结果总是在方法返回之前设置?

你想要的标志是/definiteAssignment:2

  /definiteAssignment:<n>
      0 - ignores definite-assignment rules; this mode is for testing only--it is
          not sound
      1 (default) - enforces definite-assignment rules for compiled variables and fields
          whose types do not support auto-initialization and for ghost variables
          and fields whose type is possibly empty
      2 - enforces definite-assignment for all non-yield-parameter
          variables and fields, regardless of their types
      3 - like 2, but also performs checks in the compiler that no nondeterministic
          statements are used; thus, a program that passes at this level 3 is one
          that the language guarantees that values seen during execution will be
          the same in every run of the program

这就是 Dafny 在您的代码中使用该标志所说的内容:

test.dfy(5,0): Error: out-parameter 'r', which is subject to definite-assignment rules, may be uninitialized at this return point

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM