Skip to content

Conversation

AaronRobinsonMSFT
Copy link
Member

Fixes #119875

Handle the case where there is an ambiguous name and signature match, but one is generic and the other isn't.

Validated new test on coreclr, native AOT and mono.

Handle the case where there is an ambiguous name and signature match, but one is generic and the other isn't.
@AaronRobinsonMSFT
Copy link
Member Author

This needs to be ported to both .NET 10 and 9 when verified.

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 fixes an issue with UnsafeAccessor ambiguity when there are methods with the same name and signature, but one is generic and the other is not. The fix ensures proper handling of generic method resolution in UnsafeAccessor implementations.

Key changes:

  • Added validation for generic parameter count matching in both CoreCLR and AOT implementations
  • Restructured generic signature validation logic for better clarity
  • Added comprehensive test coverage for ambiguous method name scenarios

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/tests/baseservices/compilerservices/UnsafeAccessors/UnsafeAccessorsTests.Generics.cs Added test cases for ambiguous method names and updated existing test method names for consistency
src/coreclr/vm/unsafeaccessors.cpp Fixed generic signature validation logic to properly handle ambiguous cases
src/coreclr/tools/Common/TypeSystem/IL/UnsafeAccessors.cs Added generic parameter count validation for AOT implementation

Copy link
Contributor

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

@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 2a9066e into dotnet:main Sep 22, 2025
102 of 104 checks passed
@AaronRobinsonMSFT
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/17931516821

@AaronRobinsonMSFT
Copy link
Member Author

/backport to release/10.0

Copy link
Contributor

Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/17931525426

Copy link
Contributor

@AaronRobinsonMSFT backporting to "release/9.0-staging" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: UnsafeAccessor - ambiguous name and signature match
Using index info to reconstruct a base tree...
M	src/coreclr/tools/Common/TypeSystem/IL/UnsafeAccessors.cs
A	src/coreclr/vm/unsafeaccessors.cpp
M	src/tests/baseservices/compilerservices/UnsafeAccessors/UnsafeAccessorsTests.Generics.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/tools/Common/TypeSystem/IL/UnsafeAccessors.cs
CONFLICT (modify/delete): src/coreclr/vm/unsafeaccessors.cpp deleted in HEAD and modified in UnsafeAccessor - ambiguous name and signature match.  Version UnsafeAccessor - ambiguous name and signature match of src/coreclr/vm/unsafeaccessors.cpp left in tree.
Auto-merging src/tests/baseservices/compilerservices/UnsafeAccessors/UnsafeAccessorsTests.Generics.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 UnsafeAccessor - ambiguous name and signature match
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UnsafeAccessor ambiguity failure when a generic overload exists with the same signature

2 participants