Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/coreclr/vm/method.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2013,8 +2013,7 @@ PCODE MethodDesc::TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags

if (IsGenericMethodDefinition())
{
_ASSERTE(!"Cannot take the address of an uninstantiated generic method.");
COMPlusThrow(kInvalidProgramException);
COMPlusThrow(kInvalidOperationException, IDS_EE_CODEEXECUTION_CONTAINSGENERICVAR);
}

if (accessFlags & CORINFO_ACCESS_LDFTN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ public void InvokeUninstantiatedGenericMethod()
Assert.Throws<InvalidOperationException>(() => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.StaticGenericMethod)).Invoke(null, [null]));
}

[Fact]
public void GetFunctionPointerFromUninstantiatedGenericMethod()
{
RuntimeMethodHandle handle = typeof(MI_SubClass).GetMethod(nameof(MI_SubClass.StaticGenericMethod))!.MethodHandle;
Assert.Throws<InvalidOperationException>(() => handle.GetFunctionPointer());
}

[Fact]
public void GetHashCodeTest()
{
Expand Down
5 changes: 5 additions & 0 deletions src/mono/mono/mini/mini-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

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)

Copy link
Contributor Author

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

mono_error_set_generic_error (error, "System", "InvalidOperationException", "");
return NULL;
}

if (!mono_llvm_only) {
gpointer res = mono_jit_compile_method (method, error);
res = mini_add_method_trampoline (method, res, mono_method_needs_static_rgctx_invoke (method, TRUE), need_unbox);
Expand Down