[mcs] Count arity correctly for deeply nested types
authorMarek Safar <marek.safar@gmail.com>
Thu, 24 Nov 2016 10:58:46 +0000 (11:58 +0100)
committerMarek Safar <marek.safar@gmail.com>
Thu, 24 Nov 2016 10:58:46 +0000 (11:58 +0100)
mcs/mcs/import.cs
mcs/tests/gtest-641-lib.cs [new file with mode: 0644]
mcs/tests/gtest-641.cs [new file with mode: 0644]
mcs/tests/ver-il-net_4_x.xml

index 9518427e1a17c1fe1499516410ea4c9fde28a893..96f950551e21bd257d4a7114971fbb774d50f9aa 100644 (file)
@@ -365,7 +365,7 @@ namespace Mono.CSharp
                                        // }
                                        //
                                        if (!IsMissingType (type) && type.IsGenericTypeDefinition) {
-                                               var start_pos = spec.DeclaringType == null ? 0 : spec.DeclaringType.MemberDefinition.TypeParametersCount;
+                                               var start_pos = GetDeclaringTypesTypeParametersCount (spec);
                                                var targs = CreateGenericArguments (start_pos, type.GetGenericArguments (), dtype);
                                                spec = spec.MakeGenericType (module, targs);
                                        }
@@ -381,6 +381,17 @@ namespace Mono.CSharp
                        return tspec;
                }
 
+               static int GetDeclaringTypesTypeParametersCount (TypeSpec spec)
+               {
+                       int total = 0;
+                       while (spec.DeclaringType != null) {
+                               total += spec.DeclaringType.MemberDefinition.TypeParametersCount;
+                               spec = spec.DeclaringType;
+                       }
+
+                       return total;
+               }
+
                public MethodSpec CreateMethod (MethodBase mb, TypeSpec declaringType)
                {
                        Modifiers mod = ReadMethodModifiers (mb, declaringType);
diff --git a/mcs/tests/gtest-641-lib.cs b/mcs/tests/gtest-641-lib.cs
new file mode 100644 (file)
index 0000000..4d1813c
--- /dev/null
@@ -0,0 +1,15 @@
+// Compiler options: -t:library
+
+public class Foo<T>
+{
+       public class Bar
+       {
+               public class FooBar : System.IEquatable<FooBar>
+               {
+                       public bool Equals(FooBar a)
+                       {
+                               return true;
+                       }
+               }
+       }
+}
\ No newline at end of file
diff --git a/mcs/tests/gtest-641.cs b/mcs/tests/gtest-641.cs
new file mode 100644 (file)
index 0000000..51f563f
--- /dev/null
@@ -0,0 +1,11 @@
+// Compiler options: -r:gtest-641-lib.dll
+
+using System;
+
+class SomeClass
+{
+       public static void Main ()
+       {
+               IEquatable<Foo<int>.Bar.FooBar> a = new Foo<int>.Bar.FooBar ();
+       }
+}
index 4502b9b63be1cc41c153df1602b9002b477a4fd1..b5fc91cb5f04eb053131ee9b0945832babfc734b 100644 (file)
       </method>
     </type>
   </test>
+  <test name="gtest-641.cs">
+    <type name="SomeClass">
+      <method name="Void Main()" attrs="150">
+        <size>8</size>
+      </method>
+      <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">