From 6f6e6316be5e8bed85326be5467a8c73c56f14a2 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Wed, 21 Feb 2018 14:17:43 -0800 Subject: [PATCH] [runtime] Magic interfaces requires the complex stelemref to handle arrays. Fixes gh #6266 (#7038) Add System.Collections.Generic include to objects.cs --- mono/metadata/marshal.c | 5 +++++ mono/mini/objects.cs | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/mono/metadata/marshal.c b/mono/metadata/marshal.c index 395c2b5a8474..8333eb5fbd9d 100644 --- a/mono/metadata/marshal.c +++ b/mono/metadata/marshal.c @@ -9829,6 +9829,11 @@ get_virtual_stelemref_kind (MonoClass *element_class) return STELEMREF_OBJECT; if (is_monomorphic_array (element_class)) return STELEMREF_SEALED_CLASS; + + /* magic ifaces requires aditional checks for when the element type is an array */ + if (MONO_CLASS_IS_INTERFACE (element_class) && element_class->is_array_special_interface) + return STELEMREF_COMPLEX; + /* Compressed interface bitmaps require code that is quite complex, so don't optimize for it. */ if (MONO_CLASS_IS_INTERFACE (element_class) && !mono_class_has_variant_generic_params (element_class)) #ifdef COMPRESSED_INTERFACE_BITMAP diff --git a/mono/mini/objects.cs b/mono/mini/objects.cs index 97ca3c180115..b6e1246fc74a 100644 --- a/mono/mini/objects.cs +++ b/mono/mini/objects.cs @@ -1,6 +1,7 @@ using System; using System.Text; using System.Reflection; +using System.Collections.Generic; using System.Runtime.InteropServices; using System.Runtime.CompilerServices; @@ -1829,6 +1830,30 @@ public static int test_0_typedref () { return 0; } + + public interface IFoo + { + int MyInt { get; } + } + + public class IFooImpl : IFoo + { + public int MyInt => 0; + } + + //gh 6266 + public static int test_0_store_to_magic_iface_array () + { + ICollection arr1 = new IFooImpl[1] { new IFooImpl() }; + ICollection arr2 = new IFooImpl[1] { new IFooImpl() }; + + ICollection[] a2d = new ICollection[2] { + arr1, + arr2, + }; + + return 0; + } } #if __MOBILE__