diff --git a/mono/metadata/class-init.c b/mono/metadata/class-init.c index 05fdb837044fd..d963b7c88c85a 100644 --- a/mono/metadata/class-init.c +++ b/mono/metadata/class-init.c @@ -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) diff --git a/mono/tests/Makefile.am b/mono/tests/Makefile.am index 33141ee5338c7..5e89b9f325aa2 100755 --- a/mono/tests/Makefile.am +++ b/mono/tests/Makefile.am @@ -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 diff --git a/mono/tests/bug-gh-9507.cs b/mono/tests/bug-gh-9507.cs new file mode 100644 index 0000000000000..902634e4fc4ef --- /dev/null +++ b/mono/tests/bug-gh-9507.cs @@ -0,0 +1,20 @@ +using System; + +public struct TestIsInst +{ + 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 (1); + } +}