From 665968e045d5fff2d4d93a804edd4c82030f6693 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 27 Apr 2017 13:49:10 -0700 Subject: [PATCH] Allow conversions between enum and underlying type Fixes https://github.com/dotnet/corefx/issues/13816 Commit migrated from https://github.com/dotnet/coreclr/commit/24df2436dfb8cfdbca7d3f9e088234a7c303e6fa --- .../src/classlibnative/bcltype/arraynative.cpp | 24 +++++++++------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/coreclr/src/classlibnative/bcltype/arraynative.cpp b/src/coreclr/src/classlibnative/bcltype/arraynative.cpp index c54d2f3..232f59d 100644 --- a/src/coreclr/src/classlibnative/bcltype/arraynative.cpp +++ b/src/coreclr/src/classlibnative/bcltype/arraynative.cpp @@ -319,14 +319,16 @@ ArrayNative::AssignArrayEnum ArrayNative::CanAssignArrayTypeNoGC(const BASEARRAY return AssignDontKnow; } - const CorElementType srcElType = srcTH.GetSignatureCorElementType(); - const CorElementType destElType = destTH.GetSignatureCorElementType(); + const CorElementType srcElType = srcTH.GetVerifierCorElementType(); + const CorElementType destElType = destTH.GetVerifierCorElementType(); _ASSERTE(srcElType < ELEMENT_TYPE_MAX); _ASSERTE(destElType < ELEMENT_TYPE_MAX); // Copying primitives from one type to another if (CorTypeInfo::IsPrimitiveType_NoThrow(srcElType) && CorTypeInfo::IsPrimitiveType_NoThrow(destElType)) { + if (srcElType == destElType) + return AssignWillWork; if (InvokeUtil::CanPrimitiveWiden(destElType, srcElType)) return AssignPrimitiveWiden; else @@ -349,10 +351,6 @@ ArrayNative::AssignArrayEnum ArrayNative::CanAssignArrayTypeNoGC(const BASEARRAY if (srcTH.IsInterface() && destElType != ELEMENT_TYPE_VALUETYPE) return AssignMustCast; - // Enum is stored as a primitive of type dest. - if (srcTH.IsEnum() && srcTH.GetInternalCorElementType() == destElType) - return AssignWillWork; - return AssignDontKnow; } @@ -405,14 +403,16 @@ ArrayNative::AssignArrayEnum ArrayNative::CanAssignArrayType(const BASEARRAYREF return AssignWrongType; } - const CorElementType srcElType = srcTH.GetSignatureCorElementType(); - const CorElementType destElType = destTH.GetSignatureCorElementType(); + const CorElementType srcElType = srcTH.GetVerifierCorElementType(); + const CorElementType destElType = destTH.GetVerifierCorElementType(); _ASSERTE(srcElType < ELEMENT_TYPE_MAX); _ASSERTE(destElType < ELEMENT_TYPE_MAX); // Copying primitives from one type to another if (CorTypeInfo::IsPrimitiveType_NoThrow(srcElType) && CorTypeInfo::IsPrimitiveType_NoThrow(destElType)) { + if (srcElType == destElType) + return AssignWillWork; if (InvokeUtil::CanPrimitiveWiden(destElType, srcElType)) return AssignPrimitiveWiden; else @@ -435,10 +435,6 @@ ArrayNative::AssignArrayEnum ArrayNative::CanAssignArrayType(const BASEARRAYREF if (srcTH.IsInterface() && destElType != ELEMENT_TYPE_VALUETYPE) return AssignMustCast; - // Enum is stored as a primitive of type dest. - if (srcTH.IsEnum() && srcTH.GetInternalCorElementType() == destElType) - return AssignWillWork; - return AssignWrongType; } @@ -631,8 +627,8 @@ void ArrayNative::PrimitiveWiden(BASEARRAYREF pSrc, unsigned int srcIndex, BASEA TypeHandle srcTH = pSrc->GetArrayElementTypeHandle(); TypeHandle destTH = pDest->GetArrayElementTypeHandle(); - const CorElementType srcElType = srcTH.GetSignatureCorElementType(); - const CorElementType destElType = destTH.GetSignatureCorElementType(); + const CorElementType srcElType = srcTH.GetVerifierCorElementType(); + const CorElementType destElType = destTH.GetVerifierCorElementType(); const unsigned int srcSize = GetSizeForCorElementType(srcElType); const unsigned int destSize = GetSizeForCorElementType(destElType); -- 2.7.4