2003-04-19 Miguel de Icaza <miguel@ximian.com>
+ * delegate.cs (NewDelegate.Resolve): Test whether an instance
+ method is being referenced in the method group from a static
+ context, and report error 120 if so.
+
+ * expression.cs, ecore.cs (Error_UnexpectedKind): New name for
+ Error118.
+
* typemanager.cs: Add intermediate namespaces (if a namespace A.B
is created, we create the A namespace).
}
if ((source.eclass == ExprClass.Type) && (source is TypeExpr)) {
- source.Error118 ("variable or value");
+ source.Error_UnexpectedKind ("variable or value");
return null;
} else if (source is MethodGroupExpr){
((MethodGroupExpr) source).ReportUsageError ();
\r
public override Expression DoResolve (EmitContext ec)\r
{\r
- if (Arguments == null) {\r
- Report.Error (-11, loc,\r
- "Delegate creation expression takes only one argument");\r
- return null;\r
- }\r
-\r
- if (Arguments.Count != 1) {\r
- Report.Error (-11, loc,\r
- "Delegate creation expression takes only one argument");\r
+ if (Arguments == null || Arguments.Count != 1) {\r
+ Report.Error (149, loc,\r
+ "Method name expected");\r
return null;\r
}\r
\r
if (mg.InstanceExpression != null)\r
delegate_instance_expr = mg.InstanceExpression.Resolve (ec);\r
else {\r
- if (!ec.IsStatic)\r
- delegate_instance_expr = ec.This;\r
- else\r
+ if (ec.IsStatic){\r
+ if (!delegate_method.IsStatic){\r
+ Report.Error (120, loc,\r
+ "An object reference is required for the non-static method " +\r
+ delegate_method.Name);\r
+ return null;\r
+ }\r
delegate_instance_expr = null;\r
+ } else\r
+ delegate_instance_expr = ec.This;\r
}\r
\r
if (delegate_instance_expr != null)\r
Type e_type = e.Type;\r
\r
if (!TypeManager.IsDelegateType (e_type)) {\r
- Report.Error (-12, loc, "Cannot create a delegate from something " +\r
- "not a delegate or a method.");\r
+ e.Error_UnexpectedKind ("method");\r
return null;\r
}\r
\r
if ((e is TypeExpr) || (e is ComposedCast)) {
if ((flags & ResolveFlags.Type) == 0) {
- e.Error118 (flags);
+ e.Error_UnexpectedKind (flags);
return null;
}
switch (e.eclass) {
case ExprClass.Type:
if ((flags & ResolveFlags.VariableOrValue) == 0) {
- e.Error118 (flags);
+ e.Error_UnexpectedKind (flags);
return null;
}
break;
FieldInfo fi = ((FieldExpr) e).FieldInfo;
Console.WriteLine ("{0} and {1}", fi.DeclaringType, fi.Name);
- e.Error118 (flags);
+ e.Error_UnexpectedKind (flags);
return null;
}
break;
/// <summary>
/// Reports that we were expecting `expr' to be of class `expected'
/// </summary>
- public void Error118 (string expected)
+ public void Error_UnexpectedKind (string expected)
{
string kind = "Unknown";
"' where a `" + expected + "' was expected");
}
- public void Error118 (ResolveFlags flags)
+ public void Error_UnexpectedKind (ResolveFlags flags)
{
ArrayList valid = new ArrayList (10);
return null;
} else {
- expr.Error118 ("variable, indexer or property access");
+ expr.Error_UnexpectedKind ("variable, indexer or property access");
return null;
}
}
if (!(expr is MethodGroupExpr)){
- expr.Error118 (ResolveFlags.MethodGroup);
+ expr.Error_UnexpectedKind (ResolveFlags.MethodGroup);
return null;
}
if (! (ml is MethodGroupExpr)){
if (!is_struct){
- ml.Error118 ("method group");
+ ml.Error_UnexpectedKind ("method group");
return null;
}
}
AllBindingFlags, loc);
if (!(ml is MethodGroupExpr)) {
- ml.Error118 ("method group");
+ ml.Error_UnexpectedKind ("method group");
return null;
}
// As long as the type is valid
if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess ||
eclass == ExprClass.Value)) {
- ea.Expr.Error118 ("variable or value");
+ ea.Expr.Error_UnexpectedKind ("variable or value");
return null;
}
#endif
if (!(eclass == ExprClass.Variable || eclass == ExprClass.PropertyAccess ||
eclass == ExprClass.Value || eclass == ExprClass.IndexerAccess)) {
- expr.Error118 ("value, variable, property or indexer access ");
+ expr.Error_UnexpectedKind ("value, variable, property or indexer access ");
return false;
}