Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interface maps' TargetMethods array should only contain generic method definitions, not instances #98790

Merged
merged 5 commits into from
Feb 27, 2024

Conversation

kg
Copy link
Contributor

@kg kg commented Feb 22, 2024

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.

im.TargetMethods[i] = (MethodInfo)rtTypeMethodBase!;
MethodInfo targetMethod = (MethodInfo)rtTypeMethodBase!;
// https://github.com/dotnet/runtime/issues/90863
if (targetMethod.IsGenericMethod && !targetMethod.IsGenericMethodDefinition)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I'll just make this null safe.

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@kg kg merged commit b39da5c into dotnet:main Feb 27, 2024
150 of 152 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants