2008-04-07 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Mon, 7 Apr 2008 15:58:19 +0000 (15:58 -0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 7 Apr 2008 15:58:19 +0000 (15:58 -0000)
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.

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

mcs/mcs/ChangeLog
mcs/mcs/assign.cs
mcs/mcs/class.cs
mcs/mcs/decl.cs
mcs/mcs/ecore.cs
mcs/mcs/expression.cs
mcs/mcs/namespace.cs

index 807d31390db61f6da83a38a6f49c4022d11a377a..c92a8e9927fa07b362e1a5f92537c0ff8eeef4bb 100644 (file)
@@ -1,3 +1,10 @@
+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
index 6a5c34d2872608c9e0fd04f861a618fff99ed553..2fce1660dc08533d0247f16734c908aba6601421 100644 (file)
@@ -4,6 +4,7 @@
 // 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
@@ -11,6 +12,7 @@
 using System;
 using System.Reflection;
 using System.Reflection.Emit;
+using System.Collections;
 
 namespace Mono.CSharp {
 
@@ -488,12 +490,6 @@ 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;
index 83dde3051278071d96675d150e512a0e958349b7..49c1f26ebfdd2b7b27c9da950588d11853a6d1a5 100644 (file)
@@ -2858,9 +2858,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               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 {
index 190a3988364ef564356516bd0e19903872c366d5..cb514591333ce1d67e56c678f378c7fdf0434cf5 100644 (file)
@@ -1201,7 +1201,7 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name)
+               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
                {
                        return null;
                }
index dd1f86ba50f5f0edac99d9cadbd3a947d701ca60..3f7e51ad7105a5b57470978a9f3f9497314b381a 100644 (file)
@@ -3268,7 +3268,7 @@ namespace Mono.CSharp {
                                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);
 
@@ -3727,6 +3727,12 @@ namespace Mono.CSharp {
                                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)
                {
@@ -4133,7 +4139,7 @@ namespace Mono.CSharp {
                                // 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);
index bf6b18e976c8997b67211226e9bcb9f6ebf28b81..54be33ea460e818ef35a2362ae5f08607c1b84ca 100644 (file)
@@ -4502,7 +4502,7 @@ namespace Mono.CSharp {
                                        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 ());
@@ -7034,7 +7034,7 @@ namespace Mono.CSharp {
                                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;
 
index e247f388e8f3ce641d720890df9336a46d18276c..2b6eecfbf629d2ee5e1c9f6dfa3040811f3d0f3a 100644 (file)
@@ -901,13 +901,13 @@ namespace Mono.CSharp {
                /// 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 ()) {
@@ -922,12 +922,12 @@ namespace Mono.CSharp {
                        }
 
                        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)