I’m having an argument with the CodeContracts static analysis tool.
My code:
The tool tells me that instance.bar may be a null reference. I believe the opposite.
Who is right? How can I prove it wrong?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Update: It seems the problem is that invariants are not supported for static fields.
2nd Update: The method outlined below is currently the recommended solution.
A possible workaround is to create a property for
instancethatEnsures the invariants that you want to hold. (Of course, you need toAssumethem for theEnsureto be proven.) Once you have done this, you can just use the property and all the invariants should be proven correctly.Here’s your example using this method: