From e8417c18fe9d0467669cfb388aa51acd79b52fc3 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 2 Dec 2019 13:20:00 -0300 Subject: [PATCH] [DIM] Fix behavior when there is an override of a method in a generic interface. (mono/mono#17963) * Fix behavior when there is an override of a method in a generic interface. Fixes mono/mono#17869 Commit migrated from https://github.com/mono/mono/commit/3834be3d2242312a6284f89ed77b60ff8b2327ab --- src/mono/mono/metadata/class-init.c | 2 ++ src/mono/mono/tests/Makefile.am | 1 + src/mono/mono/tests/dim-generic.cs | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/mono/mono/tests/dim-generic.cs diff --git a/src/mono/mono/metadata/class-init.c b/src/mono/mono/metadata/class-init.c index 7ffda47..7bdd00a 100644 --- a/src/mono/mono/metadata/class-init.c +++ b/src/mono/mono/metadata/class-init.c @@ -3030,6 +3030,8 @@ mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int o if (decl->is_inflated) { override = mono_class_inflate_generic_method_checked (override, mono_method_get_context (decl), error); mono_error_assert_ok (error); + } else if (mono_class_is_gtd (override->klass)) { + override = mono_class_inflate_generic_method_full_checked (override, ic, mono_class_get_context (ic), error); } if (!apply_override (klass, ic, vtable, decl, override, &override_map, &override_class_map, &conflict_map)) goto fail; diff --git a/src/mono/mono/tests/Makefile.am b/src/mono/mono/tests/Makefile.am index 45871d6..888f81f 100755 --- a/src/mono/mono/tests/Makefile.am +++ b/src/mono/mono/tests/Makefile.am @@ -384,6 +384,7 @@ TESTS_CS_SRC= \ reflection.cs \ interface.cs \ interface-2.cs \ + dim-generic.cs \ iface.cs \ iface2.cs \ iface3.cs \ diff --git a/src/mono/mono/tests/dim-generic.cs b/src/mono/mono/tests/dim-generic.cs new file mode 100644 index 0000000..c6254f0 --- /dev/null +++ b/src/mono/mono/tests/dim-generic.cs @@ -0,0 +1,34 @@ +using System; + + +interface IBaseThingy +{ + int Foo (); +} + +interface INativeThingy : IBaseThingy +{ + int IBaseThingy.Foo () { + return 0; + } +} + +class NativeThingy : INativeThingy +{ +} + +public class Test +{ + public static int test_0_dim_override() + { + var thingy = new NativeThingy (); + var ithingy = (IBaseThingy)thingy; + int i = ithingy.Foo (); + return i; + } + + public static int Main (string[] args) { + return TestDriver.RunTests (typeof (Test), args); + } + +} -- 2.7.4