[DIM] Fix behavior when there is an override of a method in a generic interface....
authorThays Grazia <thaystg@gmail.com>
Mon, 2 Dec 2019 16:20:00 +0000 (13:20 -0300)
committerGitHub <noreply@github.com>
Mon, 2 Dec 2019 16:20:00 +0000 (13:20 -0300)
* 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
src/mono/mono/tests/Makefile.am
src/mono/mono/tests/dim-generic.cs [new file with mode: 0644]

index 7ffda47..7bdd00a 100644 (file)
@@ -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;
index 45871d6..888f81f 100755 (executable)
@@ -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 (file)
index 0000000..c6254f0
--- /dev/null
@@ -0,0 +1,34 @@
+using System;
+
+
+interface IBaseThingy
+{
+       int Foo ();
+}
+
+interface INativeThingy<T> : IBaseThingy
+{
+       int IBaseThingy.Foo () {
+               return 0;
+        }
+}
+
+class NativeThingy : INativeThingy<string>
+{
+}
+
+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);
+       }
+
+}