+2008-04-07 Marek Safar <marek.safar@gmail.com>
+
+ A fix for bug #377485
+ * assign.cs, expression.cs, decl.cs, class.cs, ecore.cs, namespace.cs:
+ Propagate location for extension method groups. Report conversion failure at
+ right place.
+
2008-04-07 Marek Safar <marek.safar@gmail.com>
* anonymous.cs, expression.cs, ecore.cs, typemanager.cs: Implemented
// Author:
// Miguel de Icaza (miguel@ximian.com)
// Martin Baulig (martin@ximian.com)
+// Marek Safar (marek.safar@gmail.com)
//
// (C) 2001, 2002, 2003 Ximian, Inc.
// (C) 2004 Novell, Inc
using System;
using System.Reflection;
using System.Reflection.Emit;
+using System.Collections;
namespace Mono.CSharp {
}
}
- if (source.eclass == ExprClass.MethodGroup && !TypeManager.IsDelegateType (target_type)) {
- Report.Error (428, source.Location, "Cannot convert method group `{0}' to non-delegate type `{1}'. Did you intend to invoke the method?",
- ((MethodGroupExpr)source).Name, target.GetSignatureForError ());
- return null;
- }
-
source = Convert.ImplicitConversionRequired (ec, source, target_type, loc);
if (source == null)
return null;
}
}
- public override ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name)
+ public override ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
- return NamespaceEntry.LookupExtensionMethod (extensionType, this, name);
+ return NamespaceEntry.LookupExtensionMethod (extensionType, this, name, loc);
}
protected override TypeAttributes TypeAttr {
return null;
}
- public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name)
+ public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
{
return null;
}
return null;
// Search continues
- ExtensionMethodGroupExpr e = ns.LookupExtensionMethod (type, null, Name);
+ ExtensionMethodGroupExpr e = ns.LookupExtensionMethod (type, null, Name, loc);
if (e == null)
return base.OverloadResolve (ec, ref arguments, false, loc);
Report.Error (1503, loc, "Argument {0}: Cannot convert type `{1}' to `{2}'", index, p1, p2);
}
}
+
+ public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type target, bool expl)
+ {
+ Report.Error (428, loc, "Cannot convert method group `{0}' to non-delegate type `{1}'. Consider using parentheses to invoke the method",
+ Name, TypeManager.CSharpName (target));
+ }
protected virtual int GetApplicableParametersCount (MethodBase method, ParameterData parameters)
{
// not an extension method. We start extension methods lookup from here
//
if (InstanceExpression != null) {
- ExtensionMethodGroupExpr ex_method_lookup = ec.TypeContainer.LookupExtensionMethod (type, Name);
+ ExtensionMethodGroupExpr ex_method_lookup = ec.TypeContainer.LookupExtensionMethod (type, Name, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = InstanceExpression;
ex_method_lookup.SetTypeArguments (type_arguments);
return null;
}
- mg = ec.TypeContainer.LookupExtensionMethod (me.Type, me.Name);
+ mg = ec.TypeContainer.LookupExtensionMethod (me.Type, me.Name, loc);
if (mg == null) {
Report.Error (1955, loc, "The member `{0}' cannot be used as method or delegate",
expr_resolved.GetSignatureForError ());
if (expr_eclass == ExprClass.Value || expr_eclass == ExprClass.Variable ||
expr_eclass == ExprClass.IndexerAccess || expr_eclass == ExprClass.PropertyAccess ||
expr_eclass == ExprClass.EventAccess) {
- ExtensionMethodGroupExpr ex_method_lookup = ec.TypeContainer.LookupExtensionMethod (expr_type, Identifier);
+ ExtensionMethodGroupExpr ex_method_lookup = ec.TypeContainer.LookupExtensionMethod (expr_type, Identifier, loc);
if (ex_method_lookup != null) {
ex_method_lookup.ExtensionExpression = expr_resolved;
/// Does extension methods look up to find a method which matches name and extensionType.
/// Search starts from this namespace and continues hierarchically up to top level.
///
- public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name)
+ public ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, ClassOrStruct currentClass, string name, Location loc)
{
ArrayList candidates = null;
if (currentClass != null) {
candidates = ns.LookupExtensionMethod (extensionType, currentClass, name, this);
if (candidates != null)
- return new ExtensionMethodGroupExpr (candidates, this, extensionType, Location.Null);
+ return new ExtensionMethodGroupExpr (candidates, this, extensionType, loc);
}
foreach (Namespace n in GetUsingTable ()) {
}
if (candidates != null)
- return new ExtensionMethodGroupExpr (candidates, parent, extensionType, Location.Null);
+ return new ExtensionMethodGroupExpr (candidates, parent, extensionType, loc);
if (parent == null)
return null;
- return parent.LookupExtensionMethod (extensionType, currentClass, name);
+ return parent.LookupExtensionMethod (extensionType, currentClass, name, loc);
}
public FullNamedExpression LookupNamespaceOrType (DeclSpace ds, string name, Location loc, bool ignore_cs0104)