Skip to content

Conversation

akoeplinger
Copy link
Member

@akoeplinger akoeplinger commented Sep 15, 2025

There's a Roslyn bug where the suggestion severity for dotnet_style_null_propagation in .editorconfig incorrectly overrides the IDE0031 warning 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

@akoeplinger akoeplinger requested a review from sbomer as a code owner September 15, 2025 16:05
@Copilot Copilot AI review requested due to automatic review settings September 15, 2025 16:05
@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Sep 15, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 operator Exception?.

@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Sep 15, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/illink
See info in area-owners.md if you want to be subscribed.

@akoeplinger akoeplinger changed the title Use null-coalescing operator in LocalDataFlowState.cs Simplify null check in LocalDataFlowState.cs Sep 15, 2025
@filipnavara
Copy link
Member

I don't think this is the only affected place. It would make sense to flip suggestion to warning in
.editorconfig and then run the whole CI with consistent application of the rules.

@akoeplinger
Copy link
Member Author

Yeah. I wanted to just fix this first since we see it on internal official builds.

@filipnavara
Copy link
Member

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.

@akoeplinger
Copy link
Member Author

ah ok

@filipnavara
Copy link
Member

/Users/filipnavara/Projects/runtime/src/tools/illink/src/linker/Linker/DynamicDependency.cs(108,13): error IDE0031: Null check can be simplified (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0031) [/Users/filipnavara/Projects/runtime/src/tools/illink/src/linker/Mono.Linker.csproj]

@akoeplinger
Copy link
Member Author

yeah. there's also a lot more in corelib

@sbomer
Copy link
Member

sbomer commented Sep 15, 2025

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.

@akoeplinger
Copy link
Member Author

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
@akoeplinger akoeplinger changed the title Simplify null check in LocalDataFlowState.cs Simplify null checks to fix IDE0031 Sep 15, 2025
@akoeplinger
Copy link
Member Author

Opened #119755 to "backport" this to 10.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

runtime root build fails on Windows

3 participants