diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index dc6e35862ea29..dca64cab11ce0 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -1183,8 +1183,10 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound mono_class_setup_supertypes (klass); - if (mono_class_is_ginst (eclass)) - mono_class_init_internal (eclass); + // NOTE: this is probably too aggressive if eclass is not a valuetype. It looks like we + // only need the size info in order to set MonoClass:has_references for this array type - + // and for that we only need to setup the fields of the element type if it's not a reference + // type. if (!eclass->size_inited) mono_class_setup_fields (eclass); mono_class_set_type_load_failure_causedby_class (klass, eclass, "Could not load array element type"); diff --git a/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj b/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj new file mode 100644 index 0000000000000..32355f272f908 --- /dev/null +++ b/src/tests/Loader/classloader/regressions/GitHub_85821/GitHub_85821.csproj @@ -0,0 +1,9 @@ + + + true + Exe + + + + + diff --git a/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs new file mode 100644 index 0000000000000..7c6d52f7932eb --- /dev/null +++ b/src/tests/Loader/classloader/regressions/GitHub_85821/repro.cs @@ -0,0 +1,53 @@ +using System; + +/* Regression test for https://github.com/dotnet/runtime/issues/85821 + * ensure that self-referencing generic instances are initialized correctly and don't TLE + */ + +public class Program +{ + public static int Main() + { + var test = typeof(Node); + var fit = test.GetField("Children").FieldType; + if (fit == null) + return 101; + + var test2 = typeof(Node2); + var fit2 = test2.GetField("Children").FieldType; + if (fit2 == null) + return 102; + + var test3 = typeof(NodeVT); + var fit3 = test3.GetField("Children").FieldType; + if (fit3 == null) + return 103; + + var test4 = typeof(NodeVT2); + var fit4 = test4.GetField("Children").FieldType; + if (fit4 == null) + return 104; + + return 100; + } +} + +public class Node +{ + public Node[] Children; +} + +public class Node2 +{ + public Node2[][] Children; +} + +public struct NodeVT +{ + public NodeVT[] Children; +} + +public struct NodeVT2 +{ + public NodeVT2[][] Children; +}