[mcs] Constraints checker needs to accomodate inflated base type contrained not conve...
authorMarek Safar <marek.safar@gmail.com>
Tue, 16 Jun 2015 15:52:47 +0000 (17:52 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 16 Jun 2015 15:56:40 +0000 (17:56 +0200)
mcs/mcs/generic.cs
mcs/tests/gtest-631.cs [new file with mode: 0644]
mcs/tests/gtest-632.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_5.xml

index fb7b6c79942278a404d2105f69c243ce1885d4e9..369ee5db92e12ba9d6a7406e0ae4d7601db40a00 100644 (file)
@@ -1114,14 +1114,20 @@ namespace Mono.CSharp {
                        //
                        bool found;
                        if (!TypeSpecComparer.Override.IsEqual (BaseType, other.BaseType)) {
-                               if (other.targs == null)
-                                       return false;
-
                                found = false;
-                               foreach (var otarg in other.targs) {
-                                       if (TypeSpecComparer.Override.IsEqual (BaseType, otarg)) {
-                                               found = true;
-                                               break;
+                               if (other.targs != null) {
+                                       foreach (var otarg in other.targs) {
+                                               if (TypeSpecComparer.Override.IsEqual (BaseType, otarg)) {
+                                                       found = true;
+                                                       break;
+                                               }
+                                       }
+                               } else if (targs != null) {
+                                       foreach (var targ in targs) {
+                                               if (TypeSpecComparer.Override.IsEqual (targ, other.BaseType)) {
+                                                       found = true;
+                                                       break;
+                                               }
                                        }
                                }
 
@@ -1164,18 +1170,25 @@ namespace Mono.CSharp {
 
                        // Check interfaces implementation <- definition
                        if (other.InterfacesDefined != null) {
-                               if (InterfacesDefined == null)
-                                       return false;
-
                                //
                                // Iterate over inflated interfaces
                                //
                                foreach (var oiface in other.Interfaces) {
                                        found = false;
-                                       foreach (var iface in Interfaces) {
-                                               if (TypeSpecComparer.Override.IsEqual (iface, oiface)) {
-                                                       found = true;
-                                                       break;
+
+                                       if (InterfacesDefined != null) {
+                                               foreach (var iface in Interfaces) {
+                                                       if (TypeSpecComparer.Override.IsEqual (iface, oiface)) {
+                                                               found = true;
+                                                               break;
+                                                       }
+                                               }
+                                       } else if (targs != null) {
+                                               foreach (var targ in targs) {
+                                                       if (TypeSpecComparer.Override.IsEqual (targ, oiface)) {
+                                                               found = true;
+                                                               break;
+                                                       }
                                                }
                                        }
 
@@ -1186,18 +1199,30 @@ namespace Mono.CSharp {
 
                        // Check type parameters implementation -> definition
                        if (targs != null) {
-                               if (other.targs == null)
-                                       return false;
-
                                foreach (var targ in targs) {
                                        found = false;
-                                       foreach (var otarg in other.targs) {
-                                               if (TypeSpecComparer.Override.IsEqual (targ, otarg)) {
-                                                       found = true;
-                                                       break;
+
+                                       if (other.targs != null) {
+                                               foreach (var otarg in other.targs) {
+                                                       if (TypeSpecComparer.Override.IsEqual (targ, otarg)) {
+                                                               found = true;
+                                                               break;
+                                                       }
                                                }
                                        }
 
+                                       if (other.InterfacesDefined != null && !found) {
+                                               foreach (var iface in other.Interfaces) {
+                                                       if (TypeSpecComparer.Override.IsEqual (iface, targ)) {
+                                                               found = true;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+                                       if (!found)
+                                               found = TypeSpecComparer.Override.IsEqual (targ, other.BaseType);
+
                                        if (!found)
                                                return false;
                                }
diff --git a/mcs/tests/gtest-631.cs b/mcs/tests/gtest-631.cs
new file mode 100644 (file)
index 0000000..32939c9
--- /dev/null
@@ -0,0 +1,22 @@
+public class BaseClass<TSource>
+{
+       public void DoStuff<TInput> (TInput stuff) where TInput: TSource 
+       {
+       }
+}
+
+public class MyClass: BaseClass<TInterface>, MyInterface
+{
+       public static void Main ()
+       {
+       }
+}
+
+public interface TInterface
+{
+}
+
+public interface MyInterface 
+{
+       void DoStuff<TInput> (TInput stuff) where TInput: TInterface;
+}
\ No newline at end of file
diff --git a/mcs/tests/gtest-632.cs b/mcs/tests/gtest-632.cs
new file mode 100644 (file)
index 0000000..59cbafb
--- /dev/null
@@ -0,0 +1,22 @@
+public class BaseClass<TSource>
+{
+       public void DoStuff<TInput> (TInput stuff) where TInput: TSource 
+       {
+       }
+}
+
+public class MyClass: BaseClass<TInterface>, MyInterface
+{
+       public static void Main ()
+       {
+       }
+}
+
+public class TInterface
+{
+}
+
+public interface MyInterface 
+{
+       void DoStuff<TInput> (TInput stuff) where TInput: TInterface;
+}
\ No newline at end of file
index b306de4869ad986ab7ed4a5324e0f4f171b289a2..8a0ee23c8bc2d3a1109f898847e8a0c7968026d4 100644 (file)
       </method>
     </type>
   </test>
+  <test name="dtest-061.cs">
+    <type name="Test.Program">
+      <method name="Void Main()" attrs="150">
+        <size>88</size>
+      </method>
+      <method name="Void AreEqual[A,B](A, B)" attrs="150">
+        <size>54</size>
+      </method>
+      <method name="Void ShiftTest(Int32, Int32)" attrs="134">
+        <size>2459</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+      <method name="Void .cctor()" attrs="6289">
+        <size>24</size>
+      </method>
+    </type>
+  </test>
   <test name="dtest-anontype-01.cs">
     <type name="C">
       <method name="Void Main()" attrs="150">
       </method>
     </type>
   </test>
+  <test name="gtest-631.cs">
+    <type name="BaseClass`1[TSource]">
+      <method name="Void DoStuff[TInput](TInput)" attrs="134">
+        <size>2</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="MyClass">
+      <method name="Void Main()" attrs="150">
+        <size>2</size>
+      </method>
+      <method name="Void MyInterface.DoStuff[TInput](TInput)" attrs="993">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
+  <test name="gtest-632.cs">
+    <type name="BaseClass`1[TSource]">
+      <method name="Void DoStuff[TInput](TInput)" attrs="134">
+        <size>2</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="MyClass">
+      <method name="Void Main()" attrs="150">
+        <size>2</size>
+      </method>
+      <method name="Void MyInterface.DoStuff[TInput](TInput)" attrs="993">
+        <size>8</size>
+      </method>
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+    <type name="TInterface">
+      <method name="Void .ctor()" attrs="6278">
+        <size>7</size>
+      </method>
+    </type>
+  </test>
   <test name="gtest-anontype-01.cs">
     <type name="Test">
       <method name="Int32 Main()" attrs="150">