我如何表示的方法不会返回空值?目前,这是我的代码。

第19行得到一个确保没有证明消息,即使CreateFunction假定结果是没有什么。

1         <Pure()> Public Function CreateFunction(Of TArg1, TArg2, TResult)(ByVal body As Func(Of Expression, Expression, BinaryExpression)) As Func(Of TArg1, TArg2, TResult)   
2             Contract.RequiresAlways(body IsNot Nothing)   
3             Contract.Assume(Contract.Result(Of Func(Of TArg1, TArg2, TResult))() IsNot Nothing)   
4   
5             Dim arg1 = Expression.Parameter(GetType(Integer), "arg1")   
6             Dim arg2 = Expression.Parameter(GetType(Integer), "arg2")   
7   
8   
9             Dim temp = Expression.Lambda(body(arg1, arg2), arg1, arg2)   
10             Contract.Assume(temp IsNot Nothing)   
11             Return DirectCast(temp.Compile, Global.System.Func(Of TArg1, TArg2, TResult))   
12         End Function  
13   
14         <Pure()> Public Function Add() As Func(Of T, T, T)   
15             Contract.Ensures(Contract.Result(Of Func(Of T, T, T))() IsNot Nothing)   
16   
17             Dim temp = CreateFunction(Of T, T, T)(AddressOf Expression.AddChecked)   
18             Return temp   
19         End Function  
有帮助吗?

解决方案

确实

Contract.Ensures(Contract.Result() != null);

工作?基本上,我想尝试削减下来,直到你找到如你所期望,并从那里不起作用最简单的情况。

- MarkusQ

其他提示

您需要在AssumeCreateFunction更改为Ensures。在此之后,你应该没问题。请记住,Assume是内部的假设,以帮助当地的静态检查。他们不是从其他方法可见。仅RequiresEnsures是交叉方法的合同。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top