Reporter | Andrew Serebryansky (andrew.serebryansky) |
---|---|
Created | May 4, 2010 2:21:09 PM |
Updated | Dec 27, 2011 8:32:27 PM |
Priority | Show-stopper |
Type | Bug |
Fix versions | Next |
State | Open |
Assignee | Alexey Kuptsov (alexey.kuptsov) |
Subsystem | No subsystem |
Affected versions | 5.0 |
Fixed in build | No Fixed in build |
When the CONTRACTS_FULL symbol is defined through the "Code Contracts" tab of the project properties, ReSharper ignores it when checking whether methods will be compiled.
I wrote a simple demo application using Code Contracts:
using System.Diagnostics.Contracts;
using System;
class Program {
static void Foo(string bar) {
Contract.Requires(bar != null);
}
static void Main(string[] args) {
Console.WriteLine("CONTRACTS_FULL not defined"); #endif
Foo(null);
}
}
In the "Code Contracts" tab of the project properties, I've checked "Perform Runtime Contract Checking" (Full) and "Assert on Contract Failure".
As expected, when run, the code prints "CONTRACTS_FULL defined", then throws an assertion (because bar is null). Both proves that the CONTRACTS_FULL symbol is indeed defined.
Also as expected, in the editor, the first WriteLine is displayed as active, while the second is grayed out - suggesting that ReSharper does recognize that the CONTRACTS_FULL symbol is defined.
However, in Foo(), the Contract.Requires() line is grayed out, stating "Method invocation is skipped. Compiler will not generate method invocation because the method is conditional, or it is partial method without implementation."
This is wrong. Contract.Requires() is defined with the [Conditional("CONTRACTS_FULL")] attribute. As demonstrated by running the application, this symbol is defined and Contract.Requires() is indeed executed.
I wrote a simple demo application using Code Contracts:
using System.Diagnostics.Contracts;
using System;
class Program {
static void Foo(string bar) {
Contract.Requires(bar != null);
}
static void Main(string[] args) {
- if CONTRACTS_FULL
Console.WriteLine("CONTRACTS_FULL not defined"); #endif
Foo(null);
}
}
In the "Code Contracts" tab of the project properties, I've checked "Perform Runtime Contract Checking" (Full) and "Assert on Contract Failure".
As expected, when run, the code prints "CONTRACTS_FULL defined", then throws an assertion (because bar is null). Both proves that the CONTRACTS_FULL symbol is indeed defined.
Also as expected, in the editor, the first WriteLine is displayed as active, while the second is grayed out - suggesting that ReSharper does recognize that the CONTRACTS_FULL symbol is defined.
However, in Foo(), the Contract.Requires() line is grayed out, stating "Method invocation is skipped. Compiler will not generate method invocation because the method is conditional, or it is partial method without implementation."
This is wrong. Contract.Requires() is defined with the [Conditional("CONTRACTS_FULL")] attribute. As demonstrated by running the application, this symbol is defined and Contract.Requires() is indeed executed.