This repository was archived by the owner on Jul 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
Static checker cannot prove compiler-generated Expressions are created safely. #424
Copy link
Copy link
Closed
Labels
Description
Given the following case:
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
namespace ContractPerformanceTesting
{
class Program
{
static void Main(string[] args)
{
Expression<Func<IEnumerable<string>>> expr = () => new string[] { };
}
}
}
The static checker reports the following:
CodeContracts: ContractPerformanceTesting:
CodeContracts: ContractPerformanceTesting: Background contract analysis done.
1>------ Build started: Project: ContractPerformanceTesting, Configuration: Debug Any CPU ------
CodeContracts: ContractPerformanceTesting: Schedule static contract analysis.
1> elapsed time: 609.6196ms
1> elapsed time: 498.995ms
1> ContractPerformanceTesting -> C:\temp\ContractPerformanceTesting\ContractPerformanceTesting\bin\Debug\ContractPerformanceTestingAA.exe
CodeContracts: ContractPerformanceTesting: Background contract analysis started.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
CodeContracts: ContractPerformanceTesting: Time spent connecting to the cache: 00:00:01.1373628
CodeContracts: ContractPerformanceTesting: Cache used: localhost
C:\temp\ContractPerformanceTesting\ContractPerformanceTesting\Program.cs(11,4): message : CodeContracts: Suggested requires: Contract.Requires((int)(0) >= 1);
CodeContracts: ContractPerformanceTesting: Validated: 55.6 %
CodeContracts: ContractPerformanceTesting: Checked 9 assertions: 5 correct 1 unknown 2 unreached 1 false
CodeContracts: ContractPerformanceTesting: Contract density: 2.21
CodeContracts: ContractPerformanceTesting: Total methods analyzed 3
CodeContracts: ContractPerformanceTesting: Methods analyzed with a faster abstract domain 0
CodeContracts: ContractPerformanceTesting: Method analyses read from the cache 3
CodeContracts: ContractPerformanceTesting: Methods not found in the cache 0
CodeContracts: ContractPerformanceTesting: Methods with 0 warnings 2
CodeContracts: ContractPerformanceTesting: Total time 1.122sec. 374ms/method
CodeContracts: ContractPerformanceTesting: Retained 0 preconditions after filtering
CodeContracts: ContractPerformanceTesting: Inferred 0 object invariants
CodeContracts: ContractPerformanceTesting: Retained 0 object invariants after filtering
CodeContracts: ContractPerformanceTesting: Detected 0 code fixes
CodeContracts: ContractPerformanceTesting: Proof obligations with a code fix: 0
C:\temp\ContractPerformanceTesting\ContractPerformanceTesting\Program.cs(11,4): warning : CodeContracts: requires is false: initializers.Length >= 1
C:\Windows\System32\ContractPerformanceTestingAA.exe(1,1): message : CodeContracts: Checked 9 assertions: 5 correct 1 unknown 2 unreached 1 false
CodeContracts: ContractPerformanceTesting:
CodeContracts: ContractPerformanceTesting: Background contract analysis done.
The root cause is the second error (below), triggered by this contract on Expression.NewArrayInit.
Program.cs(11,4): warning : CodeContracts: requires is false: initializers.Length >= 1
The first error is a very odd side-effect, seems to be the static checker choking on the analysis.
message : CodeContracts: Suggested requires: Contract.Requires((int)(0) >= 1);