Bug 370577

Summary: gmcs is confused by generics methods with the same name when one returns void
Product: [Mono] Mono: Compilers Reporter: Jean-Baptiste Evain <jbevain>
Component: C#Assignee: Marek Safar <msafar>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None CC: casey.s.marshall, juan.wajnerman
Version: SVN   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Jean-Baptiste Evain 2008-03-13 18:56:42 UTC
Repro:

using System;

class Program {

	static void Foo (Action<string> a)
	{
		a ("action");
	}

	static T Foo<T> (Func<string, T> f)
	{
		return f ("function");
	}
	
	static void Main ()
	{
		var str = Foo (s => s);
		Console.WriteLine (str);
		Foo (s => Console.WriteLine (s));
	}
}
Comment 1 Marek Safar 2008-03-14 17:18:41 UTC
Fixed in SVN.
Comment 2 Jean-Baptiste Evain 2008-03-20 09:33:28 UTC
I still have an issue with this, more complete repro:

--
using System;

class Program
{

	static void Foo (Action<string> a)
	{
		a ("action");
	}

	static T Foo<T> (Func<string, T> f)
	{
		return f ("function");
	}

	static string Bar ()
	{
		return Foo (
			str => str.ToLower ());
	}

	static void Main ()
	{
		var str = Foo (s => s);
		Console.WriteLine (str);
		Foo (s => Console.WriteLine (s));
	}
}
--

The issue here is the Foo call in Bar. gmcs fails to find the appropriate Foo method while csc does.
Comment 3 Marek Safar 2008-03-25 14:07:39 UTC
Fixed in SVN.
Comment 4 Marek Safar 2008-04-08 08:30:07 UTC
*** Bug 377822 has been marked as a duplicate of this bug. ***
Comment 5 Casey Marshall 2008-04-09 01:46:00 UTC
I don't think the fix in SVN is correct (it appears to cause bug 378189).

The error message I get is:

pr370577.cs(18,24): error CS0121: The call is ambiguous between the following methods or properties: `Program.Foo(System.Action<string>)' and `Program.Foo<string>(System.Func<string,string>)'
pr370577.cs(6,21): (Location of the symbol related to previous error)
pr370577.cs(11,18): (Location of the symbol related to previous error)

Since Bar returns whatever 'Foo' returns, the compiler can't possibly choose 'void Foo(Action<string>)' as the correct function. The fix checked in for this seems to only check if the context returns void, that the invocation return void too.
Comment 6 Marek Safar 2008-07-08 14:57:26 UTC
Fixed in SVN.