[pull] main from dotnet:main#553
Merged
pull[bot] merged 3 commits intoMainbaseT:mainfrom Jan 13, 2026
Merged
Conversation
…rtion (#121527) When RangeCheck inspects, say, "i + cns" tree, it tries to get the "assertion-based" range for `i` via its block's `bbAssertionIn`. It's too conservative and doesn't take into account assertions created before that `i` in the block (inter-block assertions). Let's see if we can cheaply just accumulate those by hands (@AndyAyersMS's idea). A simplified version of the repro is the following (thanks @BoyBaykiller for the repro): ```cs void Test(int[] arr, int i) { arr[i] = 0; // creates 'i >= 0 && i < arr.Length' assertion i++; // same block as ^ if (i < arr.Length) arr[i] = 0; } ``` Codegen diff: ```diff ; Method Benchmarks:Test(int[],int):this (FullOpts) G_M59621_IG01: sub rsp, 40 G_M59621_IG02: mov eax, dword ptr [rdx+0x08] cmp r8d, eax jae SHORT G_M59621_IG05 mov ecx, r8d xor r10d, r10d mov dword ptr [rdx+4*rcx+0x10], r10d inc r8d cmp eax, r8d jle SHORT G_M59621_IG04 G_M59621_IG03: - cmp r8d, eax - jae SHORT G_M59621_IG05 mov eax, r8d xor ecx, ecx mov dword ptr [rdx+4*rax+0x10], ecx G_M59621_IG04: add rsp, 40 ret G_M59621_IG05: call CORINFO_HELP_RNGCHKFAIL int3 -; Total bytes of code: 56 +; Total bytes of code: 51 ```
…ts (#123088) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: Miha Zupan <mihazupan.zupan1@gmail.com>
# Fix KeyValuePair nullability detection on Mono
## Summary
Fixes incorrect nullability detection for `KeyValuePair<TKey, TValue>`
generic parameters on Mono, which was causing ASP.NET Core
DataAnnotations tests to fail.
## Problem
On Mono, `KeyValuePair<TKey, TValue>` generic parameters (`TKey` and
`TValue`) were being detected as `NotNull` instead of `Nullable`, while
CoreCLR correctly detects them as `Nullable`.
**Root Cause**: Mono's `KeyValuePair<TKey, TValue>` generic parameters
are missing the `NullableAttribute(2)` that CoreCLR has. This causes
`TryUpdateGenericParameterNullability` to return `false` and fall back
to `NullableContextAttribute(1)` = `NotNull`.
## Failing Tests
-
`Microsoft.AspNetCore.Mvc.DataAnnotations.DataAnnotationsMetadataProviderTest.IsNullableReferenceType_ReturnsFalse_ForKeyValuePairWithoutNullableConstraints`
-
`Microsoft.AspNetCore.Mvc.DataAnnotations.DataAnnotationsMetadataProviderTest.IsNullableReferenceType_ReturnsTrue_ForKeyValuePairWithNullableConstraints`
## Solution
Added special handling in `TryUpdateGenericParameterNullability` to
treat `KeyValuePair<TKey, TValue>` generic parameters as nullable by
default when nullable attributes are missing.
The fix:
1. Checks if the generic parameter belongs to
`System.Collections.Generic.KeyValuePair`2`
2. If so, sets `ReadState` and `WriteState` to `Nullable`
3. Only activates when existing attribute parsing fails (regression-safe
for CoreCLR)
## Testing
### Reproduction Case
```csharp
using System;
using System.Collections.Generic;
using System.Reflection;
var kvpType = typeof(KeyValuePair<string, object>);
var keyProperty = kvpType.GetProperty("Key");
var nullabilityContext = new NullabilityInfoContext();
var result = nullabilityContext.Create(keyProperty);
Console.WriteLine($"ReadState: {result.ReadState}");
// Expected: Nullable
// Mono (before fix): NotNull
// Mono (after fix): Nullable
```
### Test Results
- **Before fix**: 361 pass, 3 fail (including 2 KeyValuePair tests)
- **After fix**: 363 pass, 1 fail (KeyValuePair tests now pass)
- **Net improvement**: +2 tests fixed, 0 regressions
## Files Changed
-
`src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs`
## Verification
The fix has been tested with the full ASP.NET Core DataAnnotations test
suite and successfully resolves the failing tests without introducing
regressions.
cc: @giritrivedi
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )