-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Simplify null checks to fix IDE0031 #119722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
suggestion
severity fordotnet_style_null_propagation
in .editorconfig incorrectly overrides the IDE0031warning
severity 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