Skip to content

Commit 156b92d

Browse files
Do not generate unconstructed EEType for arrays that have a template (#113951)
When `CanonFormTypeMayExist` was written, it was okay for arrays to return false since arrays were always compared structurally (it was allowed to have multiple `MethodTable`s for a single array type). We stopped allowing this some time ago and we now have to maintain the same invariant as for any other `MethodTable` - the address of the `MethodTable` is the unique identity. We cannot allow the compiler to generate unconstructed `MethodTable` for something that can be template-constructed at runtime.
1 parent fce42d3 commit 156b92d

File tree

2 files changed

+18
-1
lines changed
  • src

2 files changed

+18
-1
lines changed

src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/EETypeNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private bool CanonFormTypeMayExist
253253
{
254254
get
255255
{
256-
if (!_type.HasInstantiation)
256+
if (_type.IsArrayTypeWithoutGenericInterfaces())
257257
return false;
258258

259259
if (!_type.Context.SupportsCanon)

src/tests/nativeaot/SmokeTests/Reflection/Reflection.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ private static int Main()
4545
TestTypesInMethodSignatures.Run();
4646

4747
TestAttributeInheritance.Run();
48+
Test113750Regression.Run();
4849
TestStringConstructor.Run();
4950
TestAssemblyAndModuleAttributes.Run();
5051
TestAttributeExpressions.Run();
@@ -1202,6 +1203,22 @@ public ClassToConstruct(int i)
12021203
}
12031204
}
12041205

1206+
class Test113750Regression
1207+
{
1208+
class Atom;
1209+
1210+
public static void Run()
1211+
{
1212+
var arr = Array.CreateInstance(GetAtom(), 0);
1213+
1214+
[MethodImpl(MethodImplOptions.NoInlining)]
1215+
static Type GetAtom() => typeof(Atom);
1216+
1217+
if (!(arr is Atom[]))
1218+
throw new Exception();
1219+
}
1220+
}
1221+
12051222
class TestStringConstructor
12061223
{
12071224
public static void Run()

0 commit comments

Comments
 (0)