What does it take to prove this Contract.Requires?

Posted by John Gietzen on Stack Overflow See other posts from Stack Overflow or by John Gietzen
Published on 2009-08-04T21:43:00Z Indexed on 2010/05/06 0:18 UTC
Read the original article Hit count: 540

I have an application that runs through the rounds in a tournament, and I am getting a contract warning on this simplified code structure:

    public static void LoadState(IList<Object> stuff)
    {
        for(int i = 0; i < stuff.Count; i++)
        {
            // Contract.Assert(i < stuff.Count);
            // Contract.Assume(i < stuff.Count);

            Object thing = stuff[i];

            Console.WriteLine(thing.ToString());
        }
    }

The warning is:

contracts: requires unproven: index < @this.Count

What am I doing wrong? How can I prove this on an IList<T>? Is this a bug in the static analyzer? How would I submit a bug report to Microsoft?

© Stack Overflow or respective owner

Related posts about c#

Related posts about design-by-contract