diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs index 975df4243c219..28e86abb80189 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/SubstitutedILProvider.cs @@ -885,6 +885,10 @@ private static bool TryExpandTypeEquality(MethodIL methodIL, byte[] body, Opcode if (!ReadGetTypeFromHandle(ref reader, methodIL, flags)) return false; + // No value in making this work for definitions + if (type1.IsGenericDefinition || type2.IsGenericDefinition) + return false; + // Dataflow runs on top of uninstantiated IL and we can't answer some questions there. // Unfortunately this means dataflow will still see code that the rest of the system // might have optimized away. It should not be a problem in practice. diff --git a/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs b/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs index d54c801ccee3e..bf4b8639cefa0 100644 --- a/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs +++ b/src/tests/nativeaot/SmokeTests/TrimmingBehaviors/DeadCodeElimination.cs @@ -340,6 +340,8 @@ public static void Run() class TestTypeEquals { + sealed class Gen { } + sealed class Never { } static Type s_type = null; @@ -350,6 +352,9 @@ public static void Run() // despite the typeof Console.WriteLine(s_type == typeof(Never)); + // This was a compiler crash + Console.WriteLine(typeof(object) == typeof(Gen<>)); + #if !DEBUG ThrowIfPresent(typeof(TestTypeEquals), nameof(Never)); #endif