From 797050d330568f42a20b0c01f06e1bd508e1edfa Mon Sep 17 00:00:00 2001 From: Jan Vorlicek Date: Mon, 30 Nov 2020 21:54:41 +0100 Subject: [PATCH] Fix problem with covariant returns with RuntimeType Ben Adams has tried to add usage of covariant returns for the RuntimeType as the overriding return type and it has uncovered an ordering issue in the SystemDomain::LoadBaseSystemClasses w.r.t. This change fixes it by shuffling parts of initialization around a bit. --- src/coreclr/src/vm/appdomain.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/coreclr/src/vm/appdomain.cpp b/src/coreclr/src/vm/appdomain.cpp index f703b4214cea61..792f0caa593bd4 100644 --- a/src/coreclr/src/vm/appdomain.cpp +++ b/src/coreclr/src/vm/appdomain.cpp @@ -1448,13 +1448,27 @@ void SystemDomain::LoadBaseSystemClasses() g_pEnumClass = CoreLibBinder::GetClass(CLASS__ENUM); _ASSERTE(!g_pEnumClass->IsValueType()); + // Load Array class + g_pArrayClass = CoreLibBinder::GetClass(CLASS__ARRAY); + + // Load the Object array class. + g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT] = ClassLoader::LoadArrayTypeThrowing(TypeHandle(g_pObjectClass)); + + // We have delayed allocation of CoreLib's static handles until we load the object class + CoreLibBinder::GetModule()->AllocateRegularStaticHandles(DefaultDomain()); + + // Make sure all primitive types are loaded + for (int et = ELEMENT_TYPE_VOID; et <= ELEMENT_TYPE_R8; et++) + CoreLibBinder::LoadPrimitiveType((CorElementType)et); + +#ifndef CROSSGEN_COMPILE + CastCache::Initialize(); +#endif // CROSSGEN_COMPILE + // Load System.RuntimeType g_pRuntimeTypeClass = CoreLibBinder::GetClass(CLASS__CLASS); _ASSERTE(g_pRuntimeTypeClass->IsFullyLoaded()); - // Load Array class - g_pArrayClass = CoreLibBinder::GetClass(CLASS__ARRAY); - // Calling a method on IList for an array requires redirection to a method on // the SZArrayHelper class. Retrieving such methods means calling // GetActualImplementationForArrayGenericIListMethod, which calls FetchMethod for @@ -1472,16 +1486,6 @@ void SystemDomain::LoadBaseSystemClasses() // Load Nullable class g_pNullableClass = CoreLibBinder::GetClass(CLASS__NULLABLE); - // Load the Object array class. - g_pPredefinedArrayTypes[ELEMENT_TYPE_OBJECT] = ClassLoader::LoadArrayTypeThrowing(TypeHandle(g_pObjectClass)); - - // We have delayed allocation of CoreLib's static handles until we load the object class - CoreLibBinder::GetModule()->AllocateRegularStaticHandles(DefaultDomain()); - - // Make sure all primitive types are loaded - for (int et = ELEMENT_TYPE_VOID; et <= ELEMENT_TYPE_R8; et++) - CoreLibBinder::LoadPrimitiveType((CorElementType)et); - CoreLibBinder::LoadPrimitiveType(ELEMENT_TYPE_I); CoreLibBinder::LoadPrimitiveType(ELEMENT_TYPE_U); @@ -1503,7 +1507,6 @@ void SystemDomain::LoadBaseSystemClasses() // further loading of nonprimitive types may need casting support. // initialize cast cache here. #ifndef CROSSGEN_COMPILE - CastCache::Initialize(); ECall::PopulateManagedCastHelpers(); #endif // CROSSGEN_COMPILE