Codecontracts V1.2.30312.0中的错误真实警告 [英] False True Warning from Codecontracts V1.2.30312.0
问题描述
如果您创建一个新的VB.Net Windows窗体项目,并添加以下代码:
Hi,
If you create a new VB.Net Windows Forms Project, and add the following Code:
Imports System.Diagnostics.Contracts
Public Class Form1
Friend WithEvents lv As System.Windows.Forms.ListView
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim i As Integer
Me.lv = New System.Windows.Forms.ListView
For i = lv.Columns.Count - 1 To 0 Step -1
Contract.Assume(i < lv.Columns.Count)
lv.Columns.RemoveAt(i)
With lv.Columns
Contract.Assume(i < .Count)
.RemoveAt(i)
End With
Next
End Sub
End Class
你得到这两个错误的真实警告:
You get these two false true warnings:
Form1.vb(10,13):警告:CodeContracts:requires未经证实:index< this.Count
Form1.vb(13,17):警告:CodeContracts:需要unproven:index< this.Count
Form1.vb(10,13): warning : CodeContracts: requires unproven: index < this.Count
Form1.vb(13,17): warning : CodeContracts: requires unproven: index < this.Count
当我看到第一个时,我认为原因是我通过属性访问了列,但第二个显示情况并非如此。
As I saw the first one, I assumed that the reason was that I accessed the Columns via the property, but the second one shows that's not the case.
推荐答案
看起来System.Windows.Forms.ListView缺少Count == Columns.Count的不变量。
It looks like System.Windows.Forms.ListView is missing an invariant that Count == Columns.Count.
此外,您的假设似乎甚至没有生效以抑制丢失的不变量的余量。 绝对是一个错误。
Additionally it seems like your assumes are not even taking effect to suppress the fallout of the missing invariant. Definitely a bug.
这篇关于Codecontracts V1.2.30312.0中的错误真实警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!