[653710] Check type parameter reference type constraint recursively
authorMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 16:29:59 +0000 (16:29 +0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 14 Dec 2010 16:32:05 +0000 (16:32 +0000)
mcs/mcs/generic.cs
mcs/tests/gtest-416.cs [new file with mode: 0644]

index 3bdb004e0d3ea50a7753b6d144e605f3cf6326bb..902b3b5befaab7c4475db8b1bec5e67b4850723b 100644 (file)
@@ -723,7 +723,17 @@ namespace Mono.CSharp {
                //
                public bool IsReferenceType {
                        get {
-                               return (spec & SpecialConstraint.Class) != 0 || HasTypeConstraint;
+                               if ((spec & SpecialConstraint.Class) != 0 || HasTypeConstraint)
+                                       return true;
+
+                               if (targs != null) {
+                                       foreach (var ta in targs) {
+                                               if (TypeManager.IsReferenceType (ta))
+                                                       return true;
+                                       }
+                               }
+
+                               return false;
                        }
                }
 
diff --git a/mcs/tests/gtest-416.cs b/mcs/tests/gtest-416.cs
new file mode 100644 (file)
index 0000000..a61546e
--- /dev/null
@@ -0,0 +1,23 @@
+public class Z { }
+
+public class A<X, Y>
+       where Y : Z
+       where X : Y
+{
+       public X Foo (Y y)
+       {
+               return y as X;
+       }
+}
+
+public class Foo
+{
+       public static int Main ()
+       {
+               var a = new A<Z, Z> ();
+               if (a.Foo (new Z ()) == null)
+                       return 1;
+               
+               return 0;
+       }
+}