2009-10-15 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Thu, 15 Oct 2009 11:12:05 +0000 (11:12 -0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 15 Oct 2009 11:12:05 +0000 (11:12 -0000)
* nullable.cs, expression.cs, statement.cs, namespace.cs, ecore.cs:
Reject variable used with type arguments.

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

mcs/mcs/ChangeLog
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/namespace.cs
mcs/mcs/nullable.cs
mcs/mcs/statement.cs

index 50b6813611ab46295c0164d81d0fcc4f7cedb160..83d399e2114325583354d6d489301e093f849f5b 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-15  Marek Safar  <marek.safar@gmail.com>
+
+       * nullable.cs, expression.cs, statement.cs, namespace.cs, ecore.cs:
+       Reject variable used with type arguments.
+
 2009-10-14  Marek Safar  <marek.safar@gmail.com>
 
        * argument.cs, dynamic.cs, assign.cs, expression.cs, ecore.cs:
index d59f9d340ead623e25d46ee745ca45df69b35463..2a414d915059b6017bd82509962ffcfe8848c1da 100644 (file)
@@ -413,6 +413,22 @@ namespace Mono.CSharp {
                        Report.Error (841, loc, "A local variable `{0}' cannot be used before it is declared", name);
                }
 
+               public void Error_TypeArgumentsCannotBeUsed (Report report, Location loc)
+               {
+                       // Better message for possible generic expressions
+                       if (eclass == ExprClass.MethodGroup || eclass == ExprClass.Type) {
+                               if (this is TypeExpr)
+                                       report.SymbolRelatedToPreviousError (type);
+
+                               string name = eclass == ExprClass.Type ? ExprClassName : "method";
+                               report.Error (308, loc, "The non-generic {0} `{1}' cannot be used with the type arguments",
+                                       name, GetSignatureForError ());
+                       } else {
+                               report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments",
+                                       ExprClassName, GetSignatureForError ());
+                       }
+               }
+
                protected virtual void Error_TypeDoesNotContainDefinition (ResolveContext ec, Type type, string name)
                {
                        Error_TypeDoesNotContainDefinition (ec, loc, type, name);
@@ -2574,7 +2590,7 @@ namespace Mono.CSharp {
                                                return ct.ResolveAsTypeStep (ec, false);
                                        }
 
-                                       Namespace.Error_TypeArgumentsCannotBeUsed (fne, loc);
+                                       fne.Error_TypeArgumentsCannotBeUsed (ec.Compiler.Report, loc);
                                }
 
                                return fne;
@@ -2624,7 +2640,7 @@ namespace Mono.CSharp {
                        if (targs != null) {
                                FullNamedExpression retval = ec.LookupNamespaceOrType (SimpleName.RemoveGenericArity (Name), loc, true);
                                if (retval != null) {
-                                       Namespace.Error_TypeArgumentsCannotBeUsed (retval, loc);
+                                       retval.Error_TypeArgumentsCannotBeUsed (ec.Compiler.Report, loc);
                                        return;
                                }
                        }
@@ -2698,23 +2714,35 @@ namespace Mono.CSharp {
                        if (current_block != null){
                                LocalInfo vi = current_block.GetLocalInfo (Name);
                                if (vi != null){
-                                       LocalVariableReference var = new LocalVariableReference (ec.CurrentBlock, Name, loc);
+                                       e = new LocalVariableReference (ec.CurrentBlock, Name, loc);
+
                                        if (right_side != null) {
-                                               return var.ResolveLValue (ec, right_side);
+                                               e = e.ResolveLValue (ec, right_side);
                                        } else {
                                                ResolveFlags rf = ResolveFlags.VariableOrValue;
                                                if (intermediate)
                                                        rf |= ResolveFlags.DisableFlowAnalysis;
-                                               return var.Resolve (ec, rf);
+
+                                               e = e.Resolve (ec, rf);
                                        }
+
+                                       if (targs != null && e != null)
+                                               e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
+
+                                       return e;
                                }
 
-                               Expression expr = current_block.Toplevel.GetParameterReference (Name, loc);
-                               if (expr != null) {
+                               e = current_block.Toplevel.GetParameterReference (Name, loc);
+                               if (e != null) {
                                        if (right_side != null)
-                                               return expr.ResolveLValue (ec, right_side);
+                                               e = e.ResolveLValue (ec, right_side);
+                                       else
+                                               e = e.Resolve (ec);
+
+                                       if (targs != null && e != null)
+                                               e.Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
 
-                                       return expr.Resolve (ec);
+                                       return e;
                                }
                        }
                        
@@ -4279,7 +4307,7 @@ namespace Mono.CSharp {
                                                        }
                                                } else {
                                                        if (type_arguments != null && !TypeManager.IsGenericMethod (best_candidate)) {
-                                                               Namespace.Error_TypeArgumentsCannotBeUsed (best_candidate, loc);
+                                                               Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
                                                                return null;
                                                        }
                                                }
index 5febf96d5354582098de61d0a75b31ba60a71c0e..42c18543ceced325d1542b66e04851c2692c79b3 100644 (file)
@@ -3133,7 +3133,7 @@ namespace Mono.CSharp {
 
                                if (best_operator == null) {
                                        ec.Report.Error (34, loc, "Operator `{0}' is ambiguous on operands of type `{1}' and `{2}'",
-                                               OperName (oper), left.GetSignatureForError (), right.GetSignatureForError ());
+                                               OperName (oper), TypeManager.CSharpName (l), TypeManager.CSharpName (r));
 
                                        best_operator = po;
                                        break;
@@ -4188,7 +4188,7 @@ namespace Mono.CSharp {
                                } else {
                                        ec.Report.Error (173, loc,
                                                "Type of conditional expression cannot be determined because there is no implicit conversion between `{0}' and `{1}'",
-                                               true_expr.GetSignatureForError (), false_expr.GetSignatureForError ());
+                                               TypeManager.CSharpName (true_type), TypeManager.CSharpName (false_type));
                                        return null;
                                }
                        }                       
@@ -4291,6 +4291,11 @@ namespace Mono.CSharp {
                        return GetHoistedVariable (ec.CurrentAnonymousMethod);
                }
 
+               public override string GetSignatureForError ()
+               {
+                       return Name;
+               }
+
                public override void Emit (EmitContext ec)
                {
                        Emit (ec, false);
@@ -7654,7 +7659,7 @@ namespace Mono.CSharp {
                                if (expr_type == null)
                                        return;
 
-                               Namespace.Error_TypeArgumentsCannotBeUsed (expr_type, loc);
+                               expr_type.Error_TypeArgumentsCannotBeUsed (rc.Compiler.Report, loc);
                                return;
                        }
 
index d313700ce7e681026f14c9efb1e3596300cc7924..a21610b59586f187530b5ed54e989df658d4e575 100644 (file)
@@ -413,7 +413,7 @@ namespace Mono.CSharp {
                        if (name.IndexOf ('`') > 0) {
                                FullNamedExpression retval = Lookup (RootContext.ToplevelTypes.Compiler, SimpleName.RemoveGenericArity (name), loc);
                                if (retval != null) {
-                                       Error_TypeArgumentsCannotBeUsed (retval, loc);
+                                       retval.Error_TypeArgumentsCannotBeUsed (Report, loc);
                                        return;
                                }
                        } else {
@@ -435,29 +435,6 @@ namespace Mono.CSharp {
                                TypeManager.CSharpName(t), TypeManager.GetNumberOfTypeArguments(t).ToString());
                }
 
-               public static void Error_TypeArgumentsCannotBeUsed (FullNamedExpression expr, Location loc)
-               {
-                       if (expr is TypeExpr) {
-                               RootContext.ToplevelTypes.Compiler.Report.SymbolRelatedToPreviousError (expr.Type);
-                               Error_TypeArgumentsCannotBeUsed (loc, "type", expr.GetSignatureForError ());
-                       } else {
-                               RootContext.ToplevelTypes.Compiler.Report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments",
-                                       expr.ExprClassName, expr.GetSignatureForError ());
-                       }
-               }
-
-               public static void Error_TypeArgumentsCannotBeUsed (MethodBase mi, Location loc)
-               {
-                       RootContext.ToplevelTypes.Compiler.Report.SymbolRelatedToPreviousError (mi);
-                       Error_TypeArgumentsCannotBeUsed (loc, "method", TypeManager.CSharpSignature (mi));
-               }
-
-               static void Error_TypeArgumentsCannotBeUsed (Location loc, string type, string name)
-               {
-                       RootContext.ToplevelTypes.Compiler.Report.Error(308, loc, "The non-generic {0} `{1}' cannot be used with the type arguments",
-                               type, name);
-               }
-
                public override string GetSignatureForError ()
                {
                        return fullname;
index 0da0f4fa21ed325f13753d2030001abb819a4323..0f84d59b9e74b570bb2245e22f6b966a40829f3b 100644 (file)
@@ -603,10 +603,10 @@ namespace Mono.CSharp.Nullable
 
                        if ((Oper & Operator.EqualityMask) != 0) {
                                ec.Report.Warning (472, 2, loc, "The result of comparing value type `{0}' with null is `{1}'",
-                                               expr.GetSignatureForError (), c.AsString ());
+                                       TypeManager.CSharpName (expr.Type), c.AsString ());
                        } else {
                                ec.Report.Warning (464, 2, loc, "The result of comparing type `{0}' with null is always `{1}'",
-                                               expr.GetSignatureForError (), c.AsString ());
+                                       TypeManager.CSharpName (expr.Type), c.AsString ());
                        }
 
                        return ReducedExpression.Create (c, this);
index 84e86e6de61617b1e0c0da6fa49a7b15a180ad7d..bb4a8007f7a1b358bf618457d993b7dae3669d38 100644 (file)
@@ -4996,7 +4996,7 @@ namespace Mono.CSharp {
                {
                        ec.Report.SymbolRelatedToPreviousError (expr.Type);
                        ec.Report.Error (1674, expr.Location, "`{0}': type used in a using statement must be implicitly convertible to `System.IDisposable'",
-                               expr.GetSignatureForError ());
+                               TypeManager.CSharpName (expr.Type));
                }
 
                protected override void EmitPreTryBody (EmitContext ec)