[650850] Inflate all hoisted type parameter constraints
authorMarek Safar <marek.safar@gmail.com>
Thu, 11 Nov 2010 17:15:16 +0000 (17:15 +0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 11 Nov 2010 17:19:31 +0000 (17:19 +0000)
mcs/mcs/anonymous.cs
mcs/mcs/method.cs
mcs/tests/gtest-anon-64.cs [new file with mode: 0644]

index 10592ce26e44239340a151277c0d7f338fcac730..569500af2b1934c85e8b0c3b816c15bc2c2d4be1 100644 (file)
@@ -80,8 +80,21 @@ namespace Mono.CSharp {
                {
                        if (tparams != null) {
                                type_params = new TypeParameter[tparams.Length];
+                               var src = new TypeParameterSpec[tparams.Length];
+                               var dst = new TypeParameterSpec[tparams.Length];
+
                                for (int i = 0; i < type_params.Length; ++i) {
                                        type_params[i] = tparams[i].CreateHoistedCopy (this, spec);
+
+                                       src[i] = tparams[i].Type;
+                                       dst[i] = type_params[i].Type;
+                               }
+
+                               // A copy is not enough, inflate any type parameter constraints
+                               // using a new type parameters
+                               var inflator = new TypeParameterInflator (null, src, dst);
+                               for (int i = 0; i < type_params.Length; ++i) {
+                                       src[i].InflateConstraints (inflator, dst[i]);
                                }
                        }
                }
@@ -1589,6 +1602,9 @@ namespace Mono.CSharp {
 
                                ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
                        } else {
+                               if (delegate_method.IsGeneric)
+                                       delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
+
                                ec.Emit (OpCodes.Ldftn, delegate_method);
                        }
 
index 1cd5bf85aa688610b0173fe9796d736dc08d338f..3e97804fe22f6ecee810dff4b809a7f4a72fdc9c 100644 (file)
@@ -775,7 +775,7 @@ namespace Mono.CSharp {
                {
                }
 
-#region Properties
+               #region Properties
 
                public override TypeParameter[] CurrentTypeParameters {
                        get {
diff --git a/mcs/tests/gtest-anon-64.cs b/mcs/tests/gtest-anon-64.cs
new file mode 100644 (file)
index 0000000..91fdea2
--- /dev/null
@@ -0,0 +1,39 @@
+using System;
+
+class C<T> where T : C<T>
+{
+       public static void Foo<U> (U arg) where U : C<U>, new ()
+       {
+               var i = new U ();
+               {
+                       var ii = new U ();
+                       Func<U> f = () => i;
+                       {
+                               Action a = () => C<U>.Run (ii);
+                               a ();
+                       }
+                       f ();
+               }
+       }
+       
+       static void Run (T a)
+       {
+       }
+}
+
+class D : C<D>
+{
+}
+
+class E : C<E>
+{
+}
+
+class A
+{
+       public static int Main ()
+       {
+               D.Foo (new E ());
+               return 0;
+       }
+}
\ No newline at end of file