Open elachlan opened 2 years ago
I guess if your a building a release version then #if DEBUG
isn't hit so it causes a positive identification. Would Roslyn understand this context? Should we just add a suppression?
@elachlan IDExxxx diagnostics are in dotnet/roslyn, not dotnet/roslyn-analyzers.
This is generally by-design, and problems similar to this are applicable to all analyzers, not only IDE0031. (for example, consider a "make method static" analyzer that hits a method that can be made static only under a certain configuration)
However, for this specific case, I think a syntactic check for #if
might make sense.
In general, skipping the analysis for #if
s might have lots of false negatives, but I don't think this is the case for IDE0031.
Tagging @mavasani @CyrusNajmabadi for thoughts and for moving to dotnet/roslyn
@mavasani @CyrusNajmabadi Could you move to dotnet/roslyn, or close if by-design?
Moving to roslyn, we should check for this case in that fixer and not offer it.
Analyzer
Diagnostic ID: [IDE0031](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0031:
Use null propagation
Analyzer source
.NET7
Describe the bug
Stumbled upon in https://github.com/dotnet/winforms/pull/7902
The analyzer doesn't take into account
#if DEBUG
statements. Inside visual studio it doesn't suggest a code fix. But in CI build it fails.Steps To Reproduce
Enable the analyzer as a warning or error and build a solution with a null check and a
#if DEBUG
statement.Expected behavior
No build failure.
Actual behavior
Build Failure.
Additional context
This is blocking winforms uptake of the rule.