Fix reflection with necessary types
When I was testing #6366 in a mode we don't normally test (debug compiler with IL scanner enabled), I hit an assert around inconsistent reflection metadata for a Module type. Turns out we weren't tracking reflection on unconstructable types. Fixed that and added a test.
This commit is contained in:
Родитель
6b692b9932
Коммит
ac126222ac
|
@ -426,6 +426,13 @@ namespace ILCompiler.DependencyAnalysis
|
|||
}
|
||||
}
|
||||
|
||||
if (!ConstructedEETypeNode.CreationAllowed(_type))
|
||||
{
|
||||
// If necessary EEType is the highest load level for this type, ask the metadata manager
|
||||
// if we have any dependencies due to reflectability.
|
||||
factory.MetadataManager.GetDependenciesDueToReflectability(ref dependencies, factory, _type);
|
||||
}
|
||||
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ internal class ReflectionTest
|
|||
TestAssemblyAndModuleAttributes.Run();
|
||||
TestAttributeExpressions.Run();
|
||||
TestParameterAttributes.Run();
|
||||
TestNecessaryEETypeReflection.Run();
|
||||
|
||||
//
|
||||
// Mostly functionality tests
|
||||
|
@ -504,6 +505,25 @@ internal class ReflectionTest
|
|||
}
|
||||
}
|
||||
|
||||
class TestNecessaryEETypeReflection
|
||||
{
|
||||
struct NeverUsed { }
|
||||
|
||||
public static unsafe void Run()
|
||||
{
|
||||
Console.WriteLine(nameof(TestNecessaryEETypeReflection));
|
||||
|
||||
// Pointer types don't have a constructed EEType form but the compiler should
|
||||
// still track them as reflectable if a typeof happens.
|
||||
Type necessaryType = typeof(NeverUsed*);
|
||||
|
||||
Type neverUsedType = necessaryType.GetElementType();
|
||||
|
||||
if (neverUsedType.Name != nameof(NeverUsed))
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
class TestInterfaceMethod
|
||||
{
|
||||
interface IFoo
|
||||
|
|
Загрузка…
Ссылка в новой задаче