Repository navigation
[release/11.0] Fix Enum.Equals folding for nullable boxed arguments - #137392
Merged
Merged
Conversation
<!-- --> Boxing a nullable enum can yield `null` while retaining an exact enum type. `Enum.Equals` folding currently dereferences that argument, throwing instead of returning `false`. - **JIT:** Require a known non-null argument before comparing boxed payloads; otherwise retain the call. Preserve null-receiver exception behavior. - **Coverage:** Add nullable-boxing cases for null, equal, and unequal arguments. <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #133817 --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: EgorBo <[email protected]>
|
Azure Pipelines: Successfully started running 3 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
The JIT servicing backport received only static review, leaving nullable regression behavior unverified under optimized JIT and NativeAOT before merge.
No open issues 🎉
What changed in this PR
Backports #133826 to release/11.0 to fix incorrect NullReferenceException behavior when Enum.Equals receives a boxed nullable enum with no value.
Changes:
- Requires a known non-null argument before folding
Enum.Equalsinto a payload comparison, preserving null-receiver exception behavior. - Adds regression cases for null, equal, and unequal nullable enum arguments.
Builds and tests were not run during this review.
| File | Description |
|---|---|
src/tests/JIT/Intrinsics/EnumIntrinsics.cs |
Adds nullable enum argument regression coverage. |
src/coreclr/jit/gentree.cpp |
Prevents unsafe folding when the boxed argument may be null. |
Review effort: Balanced
Member
|
fyi @dotnet/jit-contrib |
This was referenced Nov 12, 2026
JulieLeeMSFT
approved these changes
Nov 13, 2026
Member
|
/ba-g known issues. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #133826 to release/11.0
/cc @AndyAyersMS @copilot
Customer Impact
Incorrect null reference exception from a bad JIT optimization.
#137270 noted this fix was missing in 11.0. #137382 shows that this issue can occur in the
iTextpackage.Regression
Regression in 11.0, introduced in #122779
Testing
Issue was fixed in main after 11.0 branched, not backported.
Testing in progress, will update when done.
Risk
Low, porting an existing fix from main.