Skip to content

Commit

Permalink
[runtime] Magic interfaces requires the complex stelemref to handle a…
Browse files Browse the repository at this point in the history
…rrays. Fixes gh mono#6266 (mono#7038)

Add System.Collections.Generic include to objects.cs
  • Loading branch information
kumpera authored and spatil-rythmos committed Jun 15, 2020
1 parent cb94e74 commit 7d65690
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -9837,6 +9837,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
Expand Down
25 changes: 25 additions & 0 deletions mono/mini/objects.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;

Expand Down Expand Up @@ -1829,6 +1830,30 @@ enum Mine { One, Two }

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<IFoo> arr1 = new IFooImpl[1] { new IFooImpl() };
ICollection<IFoo> arr2 = new IFooImpl[1] { new IFooImpl() };

ICollection<IFoo>[] a2d = new ICollection<IFoo>[2] {
arr1,
arr2,
};

return 0;
}
}

#if __MOBILE__
Expand Down

0 comments on commit 7d65690

Please sign in to comment.