2005-02-15 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Tue, 15 Feb 2005 03:50:54 +0000 (03:50 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 15 Feb 2005 03:50:54 +0000 (03:50 -0000)
* generic.cs (ConstructedType.Constraints): Correctly check
constraints if the argument type is a type parameter; fixes
#72326.

svn path=/trunk/mcs/; revision=40667

mcs/gmcs/ChangeLog
mcs/gmcs/generic.cs

index edfa01b5064589ba27e32b4dd091e8ea25a4741f..973569a3d2ba6efb3bea69bdce29d287b59fbbc6 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-15  Martin Baulig  <martin@ximian.com>
+
+       * generic.cs (ConstructedType.Constraints): Correctly check
+       constraints if the argument type is a type parameter; fixes
+       #72326. 
+
 2005-02-02  Martin Baulig  <martin@ximian.com>
 
        * delegate.cs (Delegate.DefineType): Report an internal error if
index 759664ed240c14a7ed53c435776e583fd1bc1c16..1dc89ba18208b5635b49f34f58c55b7fdd2b3d87 100644 (file)
@@ -1126,17 +1126,31 @@ namespace Mono.CSharp {
                        if (gc == null)
                                return true;
 
+                       bool is_class, is_struct;
+                       if (atype.IsGenericParameter) {
+                               GenericConstraints agc = TypeManager.GetTypeParameterConstraints (atype);
+                               if (agc != null) {
+                                       is_class = agc.HasReferenceTypeConstraint;
+                                       is_struct = agc.HasValueTypeConstraint;
+                               } else {
+                                       is_class = is_struct = false;
+                               }
+                       } else {
+                               is_class = atype.IsClass;
+                               is_struct = atype.IsValueType;
+                       }
+
                        //
                        // First, check the `class' and `struct' constraints.
                        //
-                       if (gc.HasReferenceTypeConstraint && !atype.IsClass) {
+                       if (gc.HasReferenceTypeConstraint && !is_class) {
                                Report.Error (452, loc, "The type `{0}' must be " +
                                              "a reference type in order to use it " +
                                              "as type parameter `{1}' in the " +
                                              "generic type or method `{2}'.",
                                              atype, ptype, DeclarationName);
                                return false;
-                       } else if (gc.HasValueTypeConstraint && !atype.IsValueType) {
+                       } else if (gc.HasValueTypeConstraint && !is_struct) {
                                Report.Error (453, loc, "The type `{0}' must be " +
                                              "a value type in order to use it " +
                                              "as type parameter `{1}' in the " +