Bug 392448

Summary: gmcs issue with lambda expression passed as delegates
Product: [Mono] Mono: Compilers Reporter: Jean-Baptiste Evain <jbevain>
Component: C#Assignee: Marek Safar <msafar>
Status: RESOLVED DUPLICATE QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None    
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-05-20 09:12:13 UTC
Repro:

--
using System;
using System.Collections;

class Test {
	public static IList Foo (Action<IList> action)
	{
		ArrayList l = new ArrayList ();
		action (l);
		return l;
	}

	public static IList Populator (IList list, IEnumerable items)
	{
		foreach (object item in items)
			list.Add (item);

		return list;
	}

	public static void Main (string [] args)
	{
		var list = Foo (l => Populator (l, args));

		foreach (object item in list)
			Console.WriteLine (item);
	}
}
--

Fails with:

[mono] ~/Desktop @ gmcs test.cs 
test.cs(22,28): error CS1502: The best overloaded method match for `Test.Foo(System.Action<System.Collections.IList>)' has some invalid arguments
test.cs(5,29): (Location of the symbol related to previous error)
test.cs(22,28): error CS1503: Argument 1: Cannot convert type `lambda expression' to `System.Action<System.Collections.IList>'
test.cs(24,17): error CS1579: foreach statement cannot operate on variables of type `object' because it does not contain a definition for `GetEnumerator' or is not accessible

That should compile and print to stdout all arguments passed to the executable.
Comment 1 Marek Safar 2008-07-08 15:02:40 UTC

*** This bug has been marked as a duplicate of bug 378189 ***