Fix a problem with 9adc7023e66a04f162efa041ff2452222a85c977. Implement constrained...
authorZoltan Varga <vargaz@gmail.com>
Wed, 17 Oct 2012 17:26:03 +0000 (19:26 +0200)
committerZoltan Varga <vargaz@gmail.com>
Wed, 17 Oct 2012 17:26:14 +0000 (19:26 +0200)
mono/mini/generics.cs
mono/mini/method-to-ir.c

index b04319a467b527729e8d20726e5f6963a1ee9666..19282df514e273e5f2da45e6208e835255b34b58 100644 (file)
@@ -959,9 +959,25 @@ class Tests {
                }
        }
 
+       class Foo3<T> where T : IComparable {
+               public static int CompareTo (T[] t) {
+                       // This is a constrained call to Enum.CompareTo ()
+                       return t[0].CompareTo (t [0]);
+               }
+       }
+
        public static int test_1_regress_constrained_iface_call_7571 () {
         var r = new Record [10];
         Foo2<Record>.Extract (r);
                return Foo2<Record>.Extract (r);
        }
+
+       enum ConstrainedEnum {
+               Val = 1
+       }
+
+       public static int test_0_regress_constrained_iface_call_enum () {
+               var r = new ConstrainedEnum [10];
+               return Foo3<ConstrainedEnum>.CompareTo (r);
+       }
 }
index ba025490237d9f89e0b985d2a05d5c16fbb41a7e..4df5f0af05aeb7a3f03b4b03be4eabd258dd755a 100644 (file)
@@ -7067,6 +7067,14 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
                                                if (slot == -1)
                                                        TYPE_LOAD_ERROR (cmethod->klass);
                                                cmethod = constrained_call->vtable [ioffset + slot];
+
+                                               if (cmethod->klass == mono_defaults.enum_class) {
+                                                       /* Enum implements some interfaces, so treat this as the first case */
+                                                       EMIT_NEW_LOAD_MEMBASE_TYPE (cfg, ins, &constrained_call->byval_arg, sp [0]->dreg, 0);
+                                                       ins->klass = constrained_call;
+                                                       sp [0] = handle_box (cfg, ins, constrained_call, mono_class_check_context_used (constrained_call));
+                                                       CHECK_CFG_EXCEPTION;
+                                               }
                                        }
                                        virtual = 0;
                                }