Question

There are certain contracts I know that the static analyzer cannot possibly prove. I can exclude certain kinds of contract violation errors from an entire function, but this is too broad-brushed. I can exclude certain violation errors by using the baseline.xml functionality, though this is essentially impossible to audit or document in a team environment.

In short, is it possible to do something like

Contract.Requires(DoesHalt() == true, ExcludeFromStaticAnalysis=true);

There are also certain contracts made in 3rd parties libraries that appear to be dead ends for the static analyzer. I'd like to disable them for static analysis. One favorite example is a contract built to a .NET graph library. The argument to a depth first search function specifying which vertex in the graph to begin the search with has a Contract.Requires which demands that vertex be a member of the graph. Sensible contract, maybe even worth executing in a debug build, but a long way from being statically provable. Yet every time I use the depth first search, I have to find a way to ignore the static violation. (It's not solvable with a Contract.Assume either)

Without the ability to partition provable stuff from unprovable stuff, I'm finding the static analysis to simply be far too noisy, even with a small clean code base.

Was it helpful?

Solution

For static analysis I know no way to do this. The runtime checker has a custom runtime with which this would be possible, but not for the static checker.

What you can do is make use of the "baseline functionality". This provides you with the possibility to hide all warnings the static checkers gives you at a certain time. These warnings are collected in a XML file, until you turn off the baseline functionality.

This can greatly reduce the static checker's noise for an existing code base.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top