Fix crossgen2 to fix some negative tests (#344)
authorJan Vorlicek <janvorli@microsoft.com>
Thu, 28 Nov 2019 14:52:10 +0000 (15:52 +0100)
committerGitHub <noreply@github.com>
Thu, 28 Nov 2019 14:52:10 +0000 (15:52 +0100)
* Fix crossgen2 to fix some negative tests

This change fixes 4 negative tests in the Loader\classloader\generics\Instantiation\Negative
folder.

The tests were trying to instantiate objects using generic definition types
without supplying generic arguments.

src/coreclr/src/tools/Common/TypeSystem/Common/MetadataFieldLayoutAlgorithm.cs
src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs

index b998f6d..c8de101 100644 (file)
@@ -17,6 +17,12 @@ namespace Internal.TypeSystem
         public override ComputedInstanceFieldLayout ComputeInstanceLayout(DefType defType, InstanceLayoutKind layoutKind)
         {
             MetadataType type = (MetadataType)defType;
+
+            if (type.IsGenericDefinition)
+            {
+                ThrowHelper.ThrowTypeLoadException(ExceptionStringID.ClassLoadGeneral, type);
+            }
+
             // CLI - Partition 1, section 9.5 - Generic types shall not be marked explicitlayout.  
             if (type.HasInstantiation && type.IsExplicitLayout)
             {
index 01e2971..cbdbb3c 100644 (file)
@@ -908,6 +908,11 @@ namespace Internal.JitInterface
             originalMethod = HandleToObject(pResolvedToken.hMethod);
             TypeDesc type = HandleToObject(pResolvedToken.hClass);
 
+            if (type.IsGenericDefinition)
+            {
+                ThrowHelper.ThrowInvalidProgramException(ExceptionStringID.InvalidProgramSpecific, HandleToObject(callerHandle));
+            }
+
             // This formula roughly corresponds to CoreCLR CEEInfo::resolveToken when calling GetMethodDescFromMethodSpec
             // (that always winds up by calling FindOrCreateAssociatedMethodDesc) at
             // https://github.com/dotnet/coreclr/blob/57a6eb69b3d6005962ad2ae48db18dff268aff56/src/vm/jitinterface.cpp#L1141