Simplify null checks to fix IDE0031#119722
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modernizes code by replacing an explicit null check with the null-coalescing operator in the LocalDataFlowState.cs file. The change simplifies the conditional assignment pattern by using the more concise ?. operator.
- Replaces
if (Exception != null)check with null-conditional operatorException?.
src/tools/illink/src/ILLink.RoslynAnalyzer/DataFlow/LocalDataFlowState.cs
Show resolved
Hide resolved
|
Tagging subscribers to this area: @dotnet/illink |
|
I don't think this is the only affected place. It would make sense to flip |
|
Yeah. I wanted to just fix this first since we see it on internal official builds. |
I did that locally and immediately run into error in a different file... hence my suggestion. |
|
ah ok |
|
|
yeah. there's also a lot more in corelib |
|
The fix probably needs to be backported too (it started showing up in #119017 (comment) which went into .NET 10). If this needs to be unblocked before fixing all instances of the error we could also add it to NoWarn temporarily. |
|
I think for 10.0 we could probably just turn IDE0031 into suggestion in eng/CodeAnalysis.src.globalconfig |
So the value in eng/CodeAnalysis.src.globalconfig takes precedence
|
Opened #119755 to "backport" this to 10.0 |
There's a Roslyn bug where the
suggestionseverity fordotnet_style_null_propagationin .editorconfig incorrectly overrides the IDE0031warningseverity set in eng/CodeAnalysis.src.globalconfig on some machines only (root cause is currently being investigated in dotnet/roslyn#80301).This causes build breaks on machines where this doesn't happen and the IDE0031 warning severity is active (because of warnings-as-errors).
This PR fixes all the instances of IDE0031 that got hidden in the codebase.
Fixes #119391