Verify type parameter constraints type parameters
authorMarek Safar <marek.safar@gmail.com>
Wed, 6 Oct 2010 11:01:04 +0000 (12:01 +0100)
committerMarek Safar <marek.safar@gmail.com>
Wed, 6 Oct 2010 11:01:35 +0000 (12:01 +0100)
mcs/mcs/generic.cs
mcs/mcs/method.cs

index 91b8b70fe045933b9cdd27edcfea83a652e5ee32..68ed4afcb0d24e78d71ee9f4e0ba8da6c039d3b3 100644 (file)
@@ -1927,7 +1927,7 @@ namespace Mono.CSharp {
                        bool ok = true;
 
                        //
-                       // The class constraint comes next.
+                       // Check the class constraint
                        //
                        if (tparam.HasTypeConstraint) {
                                if (!CheckConversion (mc, context, atype, tparam, tparam.BaseType, loc)) {
@@ -1939,7 +1939,7 @@ namespace Mono.CSharp {
                        }
 
                        //
-                       // Now, check the interfaces and type parameters constraints
+                       // Check the interfaces constraints
                        //
                        if (tparam.Interfaces != null) {
                                if (TypeManager.IsNullableType (atype)) {
@@ -1962,6 +1962,20 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       //
+                       // Check the type parameter constraint
+                       //
+                       if (tparam.TypeArguments != null) {
+                               foreach (var ta in tparam.TypeArguments) {
+                                       if (!CheckConversion (mc, context, atype, tparam, ta, loc)) {
+                                               if (mc == null)
+                                                       return false;
+
+                                               ok = false;
+                                       }
+                               }
+                       }
+
                        //
                        // Finally, check the constructor constraint.
                        //
index 6725aed2522758e5004e161de9a9b55101eb45c3..16eb2881b47c4a7e7fe6644a7960caa3c1ba11e1 100644 (file)
@@ -361,7 +361,7 @@ namespace Mono.CSharp {
                        ms.returnType = inflator.Inflate (returnType);
                        ms.parameters = parameters.Inflate (inflator);
                        if (IsGeneric)
-                               ms.constraints = TypeParameterSpec.InflateConstraints (inflator, GenericDefinition.TypeParameters);
+                               ms.constraints = TypeParameterSpec.InflateConstraints (inflator, Constraints);
 
                        return ms;
                }