Interface maps' TargetMethods array should only contain generic method definitions, not instances#98790
Merged
kg merged 5 commits intodotnet:mainfrom Feb 27, 2024
Merged
Interface maps' TargetMethods array should only contain generic method definitions, not instances#98790kg merged 5 commits intodotnet:mainfrom
kg merged 5 commits intodotnet:mainfrom
Conversation
…d definitions, not instances
jkotas
reviewed
Feb 24, 2024
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jkotas
reviewed
Feb 24, 2024
| im.TargetMethods[i] = (MethodInfo)rtTypeMethodBase!; | ||
| MethodInfo targetMethod = (MethodInfo)rtTypeMethodBase!; | ||
| // https://github.com/dotnet/runtime/issues/90863 | ||
| if (targetMethod.IsGenericMethod && !targetMethod.IsGenericMethodDefinition) |
Member
There was a problem hiding this comment.
A comment a few lines above says that targetMethod can be null. We will crash with null reference exception if that happens. Are we missing a test for it?
Member
Author
There was a problem hiding this comment.
Good question, I'll just make this null safe.
jkotas
reviewed
Feb 24, 2024
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
jkotas
approved these changes
Feb 26, 2024
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <[email protected]>
jkotas
reviewed
Feb 27, 2024
src/coreclr/System.Private.CoreLib/src/System/RuntimeType.CoreCLR.cs
Outdated
Show resolved
Hide resolved
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.
Should fix #90863.
Under some circumstances, an interface map can end up containing invalid generic method instances where a generic method definition should be. The runtime internals do not thoroughly validate generic method instances at construction time, and it's not straightforward (or necessarily possible at all) to tighten the validation to prevent these instances from making it into the runtime representation or prevent them from being constructed.
So this PR adds a simple validation check to the C# layer that exposes the interface map, and if it sees a generic method instance, it grabs the definition for that instance instead and puts it in the interface map.
Re-enables a disabled test data item that covers this scenario.