Skip to content

Commit

Permalink
[class] Ensure 'cast_class' is initialized for the type parameters of…
Browse files Browse the repository at this point in the history
… a generic class.

Fixes mono#9507
  • Loading branch information
alexischr committed Oct 17, 2018
1 parent 240407a commit d8fb9b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mono/metadata/class-init.c
Expand Up @@ -4158,6 +4158,16 @@ mono_class_init (MonoClass *klass)

if (MONO_CLASS_IS_INTERFACE (klass))
mono_class_setup_interface_id (klass);

MonoGenericInst *ginstance = mono_class_get_generic_class (klass)->context.class_inst;
for (int x = 0; x < ginstance->type_argc; x++)
{
MonoClass *type_param = mono_class_from_mono_type (ginstance->type_argv[x]);
if (m_class_get_cast_class (type_param) == m_class_get_element_class (type_param))
break; // element_class is taken care of
if (!m_class_is_inited (m_class_get_cast_class(type_param)))
mono_class_init (m_class_get_cast_class(type_param));
}
}

if (klass->parent && !klass->parent->inited)
Expand Down
3 changes: 2 additions & 1 deletion mono/tests/Makefile.am
Expand Up @@ -690,7 +690,8 @@ TESTS_CS_SRC= \
nested_type_visibility.cs \
dynamic-method-churn.cs \
verbose.cs \
generic-unmanaged-constraint.cs
generic-unmanaged-constraint.cs \
bug-gh-9507.cs

# some tests fail to compile on mcs
if CSC_IS_ROSLYN
Expand Down
20 changes: 20 additions & 0 deletions mono/tests/bug-gh-9507.cs
@@ -0,0 +1,20 @@
using System;

public struct TestIsInst<T>
{
public T[] inArray1;

public TestIsInst(int i) {
inArray1 = new T[16];

if (inArray1 is double[])
Console.WriteLine ("OK.");
}
}

public class Bug9507 // https://github.com/mono/mono/issues/9507
{
public static void Main () {
var table = new TestIsInst<ulong> (1);
}
}

0 comments on commit d8fb9b1

Please sign in to comment.