+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:
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);
return ct.ResolveAsTypeStep (ec, false);
}
- Namespace.Error_TypeArgumentsCannotBeUsed (fne, loc);
+ fne.Error_TypeArgumentsCannotBeUsed (ec.Compiler.Report, loc);
}
return fne;
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;
}
}
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;
}
}
}
} else {
if (type_arguments != null && !TypeManager.IsGenericMethod (best_candidate)) {
- Namespace.Error_TypeArgumentsCannotBeUsed (best_candidate, loc);
+ Error_TypeArgumentsCannotBeUsed (ec.Report, loc);
return null;
}
}
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;
} 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;
}
}
return GetHoistedVariable (ec.CurrentAnonymousMethod);
}
+ public override string GetSignatureForError ()
+ {
+ return Name;
+ }
+
public override void Emit (EmitContext ec)
{
Emit (ec, false);
if (expr_type == null)
return;
- Namespace.Error_TypeArgumentsCannotBeUsed (expr_type, loc);
+ expr_type.Error_TypeArgumentsCannotBeUsed (rc.Compiler.Report, loc);
return;
}
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 {
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;
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);
{
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)