2004-12-04 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Sat, 4 Dec 2004 21:48:19 +0000 (21:48 -0000)
committerMartin Baulig <martin@novell.com>
Sat, 4 Dec 2004 21:48:19 +0000 (21:48 -0000)
* convert.cs (Convert.TypeParameter_to_Null): Use the constraints
to check whether the conversion is ok.

* typemanager.cs (TypeManager.GetTypeArguments): Just return
`Type.EmptyTypes' if we're not a generic TypeContainer.

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

mcs/gmcs/ChangeLog
mcs/gmcs/convert.cs
mcs/gmcs/typemanager.cs

index 4dc597c04f6f6bedaad7aa5c80cea2080d43ac96..eb911faa2ba4ff13e0648bc734f8fd8587692864 100755 (executable)
@@ -1,3 +1,11 @@
+2004-12-04  Martin Baulig  <martin@ximian.com>
+
+       * convert.cs (Convert.TypeParameter_to_Null): Use the constraints
+       to check whether the conversion is ok.
+
+       * typemanager.cs (TypeManager.GetTypeArguments): Just return
+       `Type.EmptyTypes' if we're not a generic TypeContainer.
+
 2004-11-25  Miguel de Icaza  <miguel@ximian.com>
 
        * convert.cs (ImplicitReferenceConversionExists): A surprisingly
index fce0a2d8f1d7bf237f126fd5ce0b78163fb9ac0a..89d1ef21045a32510aac65cb9d6c50ebde12ba01 100644 (file)
@@ -52,12 +52,16 @@ namespace Mono.CSharp {
 
                static bool TypeParameter_to_Null (Type target_type)
                {
-                       if ((target_type.BaseType == null) ||
-                           (target_type.BaseType == TypeManager.value_type) ||
-                           target_type.BaseType.IsValueType)
+                       GenericConstraints gc = TypeManager.GetTypeParameterConstraints (target_type);
+                       if (gc == null)
                                return false;
 
-                       return true;
+                       if (gc.HasReferenceTypeConstraint)
+                               return true;
+                       if (gc.HasClassConstraint && !TypeManager.IsValueType (gc.ClassConstraint))
+                               return true;
+
+                       return false;
                }
 
                static Type TypeParam_EffectiveBaseType (EmitContext ec, Type t)
index be20804b5dec01df0657cea6edd5fed5cc5dd682..097c22492984f37f8d09a1c6378b2e780a44b4ce 100755 (executable)
@@ -1701,7 +1701,7 @@ public class TypeManager {
                DeclSpace tc = LookupDeclSpace (t);
                if (tc != null) {
                        if (!tc.IsGeneric)
-                               throw new InvalidOperationException ();
+                               return Type.EmptyTypes;
 
                        TypeParameter[] tparam = tc.TypeParameters;
                        Type[] ret = new Type [tparam.Length];