2007-12-27 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Thu, 27 Dec 2007 09:36:47 +0000 (09:36 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 27 Dec 2007 09:36:47 +0000 (09:36 -0000)
* ecore.cs: Report type inference errors only when arguments count matches
parameter count.

* generic.cs (NullCoalescingOperator): Cannot be applied to null.

  * expression.cs, report.cs: New warning.

  * typemanager.cs: Catch anonymous method type too.

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

mcs/mcs/ChangeLog
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/generic.cs
mcs/mcs/report.cs
mcs/mcs/typemanager.cs

index 8fa46726e831ef4bce60482e1298e7e1ec3edd57..fc2b6f8ab455f64d7376451f2ed796aa5ad406eb 100644 (file)
@@ -1,3 +1,14 @@
+2007-12-27  Marek Safar  <marek.safar@gmail.com>
+
+       * ecore.cs: Report type inference errors only when arguments count matches
+       parameter count.
+       
+       * generic.cs (NullCoalescingOperator): Cannot be applied to null.
+       
+       * expression.cs, report.cs: New warning.
+       
+       * typemanager.cs: Catch anonymous method type too.
+
 2007-12-23  Marek Safar  <marek.safar@gmail.com>
 
        A fix for bug #346379
index a7e37ba63f0481462cbf306bb154cdd2c3375cc2..b122bf5cf2d705eb1ef5236df801c8f0e5aa7957 100644 (file)
@@ -4005,33 +4005,33 @@ namespace Mono.CSharp {
                                                        return null;
                                        }
 
-                                       if (TypeManager.IsGenericMethod (best_candidate)) {
-                                               if (type_arguments == null) {
-                                                       Report.Error (411, loc,
-                                                               "The type arguments for method `{0}' cannot be inferred from " +
-                                                               "the usage. Try specifying the type arguments explicitly",
-                                                               TypeManager.CSharpSignature (best_candidate));
-                                                       return null;
-                                               }
-
-                                               Type [] g_args = TypeManager.GetGenericArguments (best_candidate);
-                                               if (type_arguments.Count != g_args.Length) {
-                                                       Report.SymbolRelatedToPreviousError (best_candidate);
-                                                       Report.Error (305, loc, "Using the generic method `{0}' requires `{1}' type argument(s)",
-                                                               TypeManager.CSharpSignature (best_candidate),
-                                                               g_args.Length.ToString ());
-                                                       return null;
-                                               }
-                                       } else {
-                                               if (type_arguments != null) {
-                                                       Namespace.Error_TypeArgumentsCannotBeUsed (best_candidate, loc);
-                                                       return null;
-                                               }
-                                       }
-                                       
                                        ParameterData pd = TypeManager.GetParameterData (best_candidate);
                                        bool cand_params = candidate_to_form != null && candidate_to_form.Contains (best_candidate);
                                        if (arg_count == pd.Count || pd.HasParams) {
+                                               if (TypeManager.IsGenericMethod (best_candidate)) {
+                                                       if (type_arguments == null) {
+                                                               Report.Error (411, loc,
+                                                                       "The type arguments for method `{0}' cannot be inferred from " +
+                                                                       "the usage. Try specifying the type arguments explicitly",
+                                                                       TypeManager.CSharpSignature (best_candidate));
+                                                               return null;
+                                                       }
+                                                               
+                                                       Type [] g_args = TypeManager.GetGenericArguments (best_candidate);
+                                                       if (type_arguments.Count != g_args.Length) {
+                                                               Report.SymbolRelatedToPreviousError (best_candidate);
+                                                               Report.Error (305, loc, "Using the generic method `{0}' requires `{1}' type argument(s)",
+                                                                       TypeManager.CSharpSignature (best_candidate),
+                                                                       g_args.Length.ToString ());
+                                                               return null;
+                                                       }
+                                               } else {
+                                                       if (type_arguments != null) {
+                                                               Namespace.Error_TypeArgumentsCannotBeUsed (best_candidate, loc);
+                                                               return null;
+                                                       }
+                                               }
+                                               
                                                if (VerifyArgumentsCompat (ec, Arguments, arg_count, best_candidate, cand_params, may_fail, loc))
                                                        throw new InternalErrorException ("Overload verification expected failure");
                                                return null;
index b62f1b39b3f121a95b73b92eb0608dc36d08b24a..deb57d9ccaf5f5b5c08b71352f1244a4bc056efe 100644 (file)
@@ -1153,7 +1153,7 @@ namespace Mono.CSharp {
                                // If E is a method group or the null literal, of if the type of E is a reference
                                // type or a nullable type and the value of E is null, the result is false
                                //
-                               if (((Constant) expr).GetValue () == null)
+                               if (expr.IsNull)
                                        return CreateConstantResult (false);
                        } else if (TypeManager.IsNullableType (d) && !TypeManager.ContainsGenericParameters (d)) {
                                d = TypeManager.GetTypeArguments (d) [0];
@@ -1319,7 +1319,11 @@ namespace Mono.CSharp {
                                }
                        }
 #endif
-
+                       if (expr.IsNull && TypeManager.IsNullableType (type)) {
+                               Report.Warning (458, 2, loc, "The result of the expression is always `null' of type `{0}'",
+                                       TypeManager.CSharpName (type));
+                       }
+                       
                        Expression e = Convert.ImplicitConversion (ec, expr, type, loc);
                        if (e != null){
                                expr = e;
index e6fcb7fbc0c940299d49ff799d7eac7e98fe65c6..296ecab09b7aceb8a696b837bcd25a9df778ffae 100644 (file)
@@ -3856,11 +3856,6 @@ namespace Mono.CSharp {
 
                                Type ltype = left.Type, rtype = right.Type;
 
-                               if (!TypeManager.IsNullableType (ltype) && ltype.IsValueType) {
-                                       Binary.Error_OperatorCannotBeApplied (loc, "??", ltype, rtype);
-                                       return null;
-                               }
-
                                if (TypeManager.IsNullableType (ltype)) {
                                        NullableInfo info = new NullableInfo (ltype);
 
@@ -3874,6 +3869,11 @@ namespace Mono.CSharp {
                                                type = expr.Type;
                                                return this;
                                        }
+                               } else {
+                                       if (left.IsNull || ltype.IsValueType) {
+                                               Binary.Error_OperatorCannotBeApplied (loc, "??", ltype, rtype);
+                                               return null;
+                                       }
                                }
 
                                expr = Convert.ImplicitConversion (ec, right, ltype, loc);
index c329d03f84c1b83ed449bed35555051b32c173fb..8bf9b1f7d3168f5991b405430b457ca70b63568d 100644 (file)
@@ -101,7 +101,7 @@ namespace Mono.CSharp {
                        2002, 2023, 2029,
                        3005, 3012, 3018, 3019, 3021, 3022, 3023, 3026, 3027,
 #if GMCS_SOURCE
-                       402, 414, 693, 1058, 1700, 3024
+                       402, 414, 458, 693, 1058, 1700, 3024
 #endif
                };
 
index a102acb3c41897a938f75ba20b9f07c62a24f2ba..5fa49a057d9649a9070eef725443a27b8b543e4a 100644 (file)
@@ -625,6 +625,9 @@ namespace Mono.CSharp {
 
                if (t == typeof (ArglistParameter))
                        return "__arglist";
+                       
+               if (t == typeof (AnonymousMethod))
+                       return "anonymous method";
 
                return CSharpName (GetFullName (t));
     }