令人难以置信的错误:涉及继承的合同无法验证方法名称何时为“包” [英] Unbelievable Bug: Contract involving inheritance fails to verify when method name is 'Pack'
问题描述
这个对我来说非常困惑。我有几个非空合同无法验证,很长一段时间我都很难为它做一个测试用例。现在我发现了原因。涉及的方法*将*命名为Pack,否则bug就会消失。
This one is extremely confusing to me. I have several non-null contracts that are failing to verify, and for a long time I had a hard time making a test case for it. Now I found out why. The method involved *has* to be named Pack, or the bug goes away.
测试用例如下。由于两个不同的原因,值绝对不为空:Pack具有非null前提条件,而T仅限于结构类型。请注意,错误不需要递归,但被调用的方法似乎也必须以
继承合同。
The test case is below. Value is definitely not null for two separate reasons: Pack has a non-null precondition and T is restricted to a structure type. Note that the recursion is not necessary for the bug, but the called method also seems to have to be inheriting contracts in the same way.
Class D(Of T As Structure)
Inherits B(Of T)
Public Overrides Sub Pack(value As T)
Pack(value) 'requires unprovent: value != null
End Sub
End Class
<ContractClass(GetType(C(Of )))>
MustInherit Class B(Of T)
Public MustOverride Sub Pack(value As T)
End Class
<ContractClassFor(GetType(B(Of )))>
MustInherit Class C(Of T)
Inherits B(Of T)
<Pure()>
Public Overrides Sub Pack(value As T)
Contract.Requires(value IsNot Nothing)
Throw New NotSupportedException
End Sub
End Class
推荐答案
Hi Strilanc,
Hi Strilanc,
我无法重现它。你使用哪些选项?你能给我(直接在我的电子邮件中)一个带有repro的小项目吗?
I cannot reproduce it. Which options are you using? Can you send me (directly at my email) a small project with the repro?
谢谢!
f
这篇关于令人难以置信的错误:涉及继承的合同无法验证方法名称何时为“包”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!