views:

45

answers:

2

I'm trying to use Contract.ForAll, and it looks like I'm missing something here.

Consider this small example:

        var l = new List<string>();
        Contract.Assume( Contract.ForAll( l, s => s != null ) );

        foreach ( var s in l ) Console.WriteLine( s.Length );

Despite the Contract.Assume call, I do get a "possible calling a method on a null reference" warning for s.Length.

Am I doing this right? Is it even supposed to work? Or am I missing something?

+1  A: 

From the Code Contracts User Manual, section 6.6.1 Current Limitations of the Checker and Bugs:

The static contract checker does not yet deal with quantifiers ForAll or Exists.

adrift
Well, that was my first thought, but I found the following question: http://stackoverflow.com/questions/3104856/using-contract-forall-in-code-contracts. The first comment to the original post indicates that the latest version should work ok.
Fyodor Soikin
Interesting... I wish he had provided a source! That comment is from July 9th, and the latest copy of the user manual is dated September 3rd. Not sure who to believe, but I am leaning towards the documentation.
adrift
I did some searching and found [this post](http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/94ec2bce-61b5-463c-a1b6-22c22a42e67f) from April 2009 indicating the static checker did not support Contract.ForAll, but that MS hoped to support it by the end of summer 2009. Then [this post](http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/20e80553-98ce-4771-8bb7-143816af3ded) from January 2010 asking about it with a response from MS that it still wasn't working. Responses to that post from a month ago indicate that it is still not supported.
adrift
Ok then, I guess I'll just have to wait... Thanks :-)
Fyodor Soikin
It's enabled but not fully completed. See the other answer :)
Porges
+1  A: 

Did you enable the "container analyses" option on the static checker Pane?

MaF