验证者不了解可空类型(足够) [英] Verifier doesn't understand nullable types (enough)

查看:90
本文介绍了验证者不了解可空类型(足够)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证者未能证明关于可空类型的简单事情。例如:


模块M 
Sub S(ByVal a As Byte?)
Contract.Requires(a.HasValue AndAlso) a.Value = 0)
结束子
子T()
S(0)
结束子
结束模块




解决方案

Strilanc,


分裂连词总是个好主意尽可能分开签订合同。如果你这样做,你会得到:



 



 



合同 。需要(x.HasValue);


合同 。要求(x.Value = 0);


如果你试试这个,静态检查器会抱怨第二个只要。所以它不是处理值部分,但它知道可空的有效。


构造函数上的契约可能不够强大,并且由于泛型而难以编写。



The verifier is failing to prove simple things about nullable types. For example:

Module M
    Sub S(ByVal a As Byte?)
        Contract.Requires(a.HasValue AndAlso a.Value = 0)
    End Sub
    Sub T()
        S(0)
    End Sub
End Module



解决方案

Strilanc,

it's always a good idea to split conjunctions into separate contracts when possible. If you do that here, you'll get:

 

 

Contract.Requires(x.HasValue);

Contract.Requires(x.Value = 0);

If you try this, the static checker will complain about the second only. So it isn't handling value part, but it knows that the nullable is valid.

The contract on the constructor is probably not strong enough and is tricky to write due to generics.


这篇关于验证者不了解可空类型(足够)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆