Use one routine for type argument scan for type parameter
authorMarek Safar <marek.safar@gmail.com>
Tue, 4 Jan 2011 11:29:09 +0000 (11:29 +0000)
committerMarek Safar <marek.safar@gmail.com>
Tue, 4 Jan 2011 11:30:40 +0000 (11:30 +0000)
mcs/mcs/expression.cs
mcs/mcs/generic.cs
mcs/mcs/linq.cs
mcs/mcs/typemanager.cs

index b2d8a20a1ab0e55c60b14562546699afb1f72983..86cdcea0723efe1332471e07db80e4bebe221172 100644 (file)
@@ -1421,7 +1421,7 @@ namespace Mono.CSharp
                                        if (TypeManager.IsGenericParameter (d))
                                                return ResolveGenericParameter (ec, t, (TypeParameterSpec) d);
 
-                                       if (TypeManager.ContainsGenericParameters (d))
+                                       if (InflatedTypeSpec.ContainsTypeParameter (d))
                                                return this;
 
                                        if (Convert.ImplicitReferenceConversionExists (expr, t) ||
@@ -1524,8 +1524,8 @@ namespace Mono.CSharp
                                return this;
                        }
                        
-                       Expression e = Convert.ImplicitConversion (ec, expr, type, loc);
-                       if (e != null){
+                       Expression e = Convert.ImplicitConversionStandard (ec, expr, type, loc);
+                       if (e != null) {
                                expr = e;
                                return this;
                        }
@@ -1538,8 +1538,7 @@ namespace Mono.CSharp
                                return this;
                        }
 
-                       if (TypeManager.ContainsGenericParameters (etype) ||
-                           TypeManager.ContainsGenericParameters (type)) {
+                       if (InflatedTypeSpec.ContainsTypeParameter (etype) || InflatedTypeSpec.ContainsTypeParameter (type)) {
                                expr = new BoxedCast (expr, etype);
                                do_isinst = true;
                                return this;
@@ -7183,24 +7182,6 @@ namespace Mono.CSharp
                        return false;
                }
 
-               static bool ContainsTypeParameter (TypeSpec type)
-               {
-                       if (type.Kind == MemberKind.TypeParameter)
-                               return true;
-
-                       var element_container = type as ElementTypeSpec;
-                       if (element_container != null)
-                               return ContainsTypeParameter (element_container.Element);
-
-                       foreach (var t in type.TypeArguments) {
-                               if (ContainsTypeParameter (t)) {
-                                       return true;
-                               }
-                       }
-
-                       return false;
-               }
-
                public override void EncodeAttributeValue (IMemberContext rc, AttributeEncoder enc, TypeSpec targetType)
                {
                        // Target type is not System.Type therefore must be object
@@ -7211,7 +7192,7 @@ namespace Mono.CSharp
                        if (!(QueriedType is GenericOpenTypeExpr)) {
                                var gt = typearg;
                                while (gt != null) {
-                                       if (ContainsTypeParameter (gt)) {
+                                       if (InflatedTypeSpec.ContainsTypeParameter (gt)) {
                                                rc.Compiler.Report.Error (416, loc, "`{0}': an attribute argument cannot use type parameters",
                                                        typearg.GetSignatureForError ());
                                                return;
index b037a87cb17185d06b6f23af55913df398576db8..e6391e49d0aae53dc31f991bd433182b5ee86ff9 100644 (file)
@@ -1401,6 +1401,24 @@ namespace Mono.CSharp {
 
                #endregion
 
+               public static bool ContainsTypeParameter (TypeSpec type)
+               {
+                       if (type.Kind == MemberKind.TypeParameter)
+                               return true;
+
+                       var element_container = type as ElementTypeSpec;
+                       if (element_container != null)
+                               return ContainsTypeParameter (element_container.Element);
+
+                       foreach (var t in type.TypeArguments) {
+                               if (ContainsTypeParameter (t)) {
+                                       return true;
+                               }
+                       }
+
+                       return false;
+               }
+
                TypeParameterInflator CreateLocalInflator ()
                {
                        TypeParameterSpec[] tparams_full;
index 7b3495eef36ee69db976b1762003212a654c52af..afda9156828f0e93f4aa9863ea55b6c0b402d0fa 100644 (file)
@@ -112,7 +112,7 @@ namespace Mono.CSharp.Linq
                                if (source_type != null) {
                                        Argument a = arguments[0];
 
-                                       if (TypeManager.IsGenericType (source_type) && TypeManager.ContainsGenericParameters (source_type)) {
+                                       if (TypeManager.IsGenericType (source_type) && InflatedTypeSpec.ContainsTypeParameter (source_type)) {
                                                TypeInferenceContext tic = new TypeInferenceContext (source_type.TypeArguments);
                                                tic.OutputTypeInference (rc, a.Expr, source_type);
                                                if (tic.FixAllTypes (rc)) {
index 7e7459726fd9a833f95b982c65aa947c7642268d..bb8f2178617b2755b630b2609c5ca1d10a827aba 100644 (file)
@@ -904,12 +904,6 @@ namespace Mono.CSharp
                return type.IsGeneric;
        }
 
-       // TODO: Implement correctly
-       public static bool ContainsGenericParameters (TypeSpec type)
-       {
-               return type.GetMetaInfo ().ContainsGenericParameters;
-       }
-
        public static TypeSpec[] GetTypeArguments (TypeSpec t)
        {
                // TODO: return empty array !!