-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Throw InvalidOperationException on RuntimeMethodHandle.GetFunctionPointer() for generic methods #104644
Conversation
…nter() for generic methods
@steveharter what should this do: public class G<T>
{
public static T Method(T x) => x;
}
public class Program
{
public static void Main()
{
var mi = typeof(G<>).GetMethod("Method", BindingFlags.Public|BindingFlags.Static);
var h = mi.MethodHandle;
var fp = h.GetFunctionPointer();
Console.WriteLine(fp);
}
} On CoreCLR this works (returns some kind of non-null value for
(same behavior on .NET 9 preview 6 and .NET 8, across both runtimes) |
src/mono/mono/mini/mini-runtime.c
Outdated
@@ -2938,6 +2938,11 @@ mono_jit_compile_method_jit_only (MonoMethod *method, MonoError *error) | |||
static gpointer | |||
get_ftnptr_for_method (MonoMethod *method, gboolean need_unbox, MonoError *error) | |||
{ | |||
if (method->is_generic) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we want to also rule out methods from a generic type definition, then you may want to add || mono_class_is_gtd (method->klass)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we should throw if the method is not callable meaning a "true" generic method and a generic method that uses the type parameters from the owning class. It seems like IsGenericMethod()
should return true
even if the type parameters come from the owning class, but that's a different problem...
I'll make another pass here. Thanks
Merging as @steveharter is out |
Fixes #101664
On CoreClr, the previous exception was InvalidProgramException. On Mono, the call caused a crash.