Skip to content

[pull] main from dotnet:main#553

Merged
pull[bot] merged 3 commits intoMainbaseT:mainfrom
dotnet:main
Jan 13, 2026
Merged

[pull] main from dotnet:main#553
pull[bot] merged 3 commits intoMainbaseT:mainfrom
dotnet:main

Conversation

@pull
Copy link
Copy Markdown

@pull pull bot commented Jan 13, 2026

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 : )

EgorBo and others added 3 commits January 13, 2026 03:24
…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
@pull pull bot locked and limited conversation to collaborators Jan 13, 2026
@pull pull bot added the ⤵️ pull label Jan 13, 2026
@pull pull bot merged commit d8182b2 into MainbaseT:main Jan 13, 2026
1 check failed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants