未验证 提交 e95a6582 编写于 作者: M Michal Strehovský 提交者: GitHub

Don't consider ShadowMethods reflectable (#67421)

Fixes #65612. This regression was exposed in #62891 - we had a mismatch between what methods are considered reflectable during scanning vs during optimized compilation due to extra array being injected for reflectable `params` methods on instantiated generic types.

There are two potential fixes - either expand the set of methods considered reflectable during scanning, or limit the number of methods considered reflectable in optimized compilation. It doesn't look like we need the expanded set, so going with a restriction instead. The CI may prove me otherwise, so keeping an open mind about this.
上级 0c1fbe03
......@@ -184,16 +184,18 @@ protected virtual void Graph_NewMarkedNode(DependencyNodeCore<NodeFactory> obj)
}
IMethodNode methodNode = methodBodyNode;
if (methodNode != null)
{
if (AllMethodsCanBeReflectable)
_reflectableMethods.Add(methodNode.Method);
}
if (methodNode == null)
methodNode = obj as ShadowConcreteMethodNode;
if (methodNode != null)
{
_methodsGenerated.Add(methodNode.Method);
if (AllMethodsCanBeReflectable)
_reflectableMethods.Add(methodNode.Method);
return;
}
......
......@@ -45,6 +45,7 @@ internal static int Run()
TestRecursionInGenericVirtualMethods.Run();
TestRecursionThroughGenericLookups.Run();
TestGvmLookupDependency.Run();
TestInvokeMemberCornerCaseInGenerics.Run();
#if !CODEGEN_CPP
TestNullableCasting.Run();
TestVariantCasting.Run();
......@@ -3168,4 +3169,26 @@ public static void Run()
CatConcepts<Technique, object>();
}
}
class TestInvokeMemberCornerCaseInGenerics
{
class Generic<T>
{
public void Method(params T[] ts) { }
}
class Atom { }
static Generic<Atom> s_instance = new Generic<Atom>();
static Type s_atomType = typeof(Atom);
public static void Run()
{
s_instance.Method(null);
// Regression test for https://github.com/dotnet/runtime/issues/65612
// This requires MethodTable for "Atom[]" - just make sure the compiler didn't crash and we can invoke
typeof(Generic<>).MakeGenericType(s_atomType).InvokeMember("Method", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, s_instance, new object[] { new Atom() });
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册