[runtime] Fix Type.GetTypeCode () for generic enums. (#34670)
authormonojenkins <jo.shields+jenkins@xamarin.com>
Wed, 8 Apr 2020 16:05:09 +0000 (12:05 -0400)
committerGitHub <noreply@github.com>
Wed, 8 Apr 2020 16:05:09 +0000 (12:05 -0400)
Fixes https://github.com/mono/mono/issues/17735.

<!--
Thank you for your Pull Request!

If you are new to contributing to Mono, please try to do your best at conforming to our coding guidelines http://www.mono-project.com/community/contributing/coding-guidelines/ but don't worry if you get something wrong. One of the project members will help you to get things landed.

Does your pull request fix any of the existing issues? Please use the following format: Fixes #issue-number
-->

Co-authored-by: vargaz <vargaz@users.noreply.github.com>
src/mono/mono/metadata/icall.c

index 35ab2bb..b07fe63 100644 (file)
@@ -2000,13 +2000,12 @@ guint32
 ves_icall_type_GetTypeCodeInternal (MonoReflectionTypeHandle ref_type, MonoError *error)
 {
        MonoType *type = MONO_HANDLE_GETVAL (ref_type, type);
-       int t = type->type;
 
        if (type->byref)
                return TYPECODE_OBJECT;
 
 handle_enum:
-       switch (t) {
+       switch (type->type) {
        case MONO_TYPE_VOID:
                return TYPECODE_OBJECT;
        case MONO_TYPE_BOOLEAN:
@@ -2041,7 +2040,7 @@ handle_enum:
                MonoClass *klass = type->data.klass;
                
                if (m_class_is_enumtype (klass)) {
-                       t = mono_class_enum_basetype_internal (klass)->type;
+                       type = mono_class_enum_basetype_internal (klass);
                        goto handle_enum;
                } else if (mono_is_corlib_image (m_class_get_image (klass))) {
                        if (strcmp (m_class_get_name_space (klass), "System") == 0) {
@@ -2072,9 +2071,13 @@ handle_enum:
                }
                return TYPECODE_OBJECT;
        case MONO_TYPE_GENERICINST:
+               if (m_class_is_enumtype (type->data.generic_class->container_class)) {
+                       type = mono_class_enum_basetype_internal (type->data.generic_class->container_class);
+                       goto handle_enum;
+               }
                return TYPECODE_OBJECT;
        default:
-               g_error ("type 0x%02x not handled in GetTypeCode()", t);
+               g_error ("type 0x%02x not handled in GetTypeCode()", type->type);
        }
        return 0;
 }