Consider the following code compiled using static analysis of code contracts:
void TestGood<T>(T arg) { Contract.Requires(arg != null); } void TestBad<T>(T arg) { Contract.Requires(null != arg); } void RunTest() { TestGood(Guid.Empty);
It seems that the order of the parameters in binary == important, which does not make much sense.
It is not limited to the type of Guid . For example, struct MyStruct { } gives the same behavior.
Oddly enough, if we pass a built-in numeric type (for example, the value is int 0 ), there will be no warning.
So the questions are:
- Is there a reason why calling
TestBad gives a warning? - If not, is this a bug in a static analyzer with a code contract?
Using contract code version 1.5.60502.11 with Visual Studio 2012. Here is a screenshot showing the settings used . In addition, as I said, I asked the same question in the code contract with the user forum .
source share