Bug 12930 - Delegate no longer inferred
Summary: Delegate no longer inferred
Status: RESOLVED FEATURE
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-06-27 20:51 UTC by t9mike
Modified: 2013-06-28 03:38 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FEATURE

Description t9mike 2013-06-27 20:51:28 UTC
In production Xamarin, the following compiles and executes OK. It does not in Alpha channel, giving error CS1660: Cannot convert `lambda expression' to non-delegate type `int'

	class TestClass1
	{
		public static void Main()
		{
			// Gives error CS1660: Cannot convert `lambda expression' to non-delegate type `int'
			var o = new TestClass2("hello", () => Callback());
		}
	}

	public class TestClass2
	{
		public TestClass2(string a, int b)
		{
		}

		public TestClass2(string a, Action callback)
		{
		}
	}

Xamarin Studio
Version 4.1.4 (build 117)
Runtime:
	Mono 3.0.12 ((no/d6c5db8)
	GTK 2.24.18
	GTK# (2.12.0.0)
	Package version: 300120000
Comment 1 t9mike 2013-06-27 21:06:37 UTC
Pasted wrong example. Here it is:

	class MainClass : BaseClass
	{
		public MainClass(string a, Action callback) : base(a, () => Callback())
		{
		}

		public MainClass(string a, int b) : base(a, b)
		{
		}

		private void Callback()
		{
		}
	}

	public class BaseClass
	{
		public BaseClass(string a, int b)
		{
		}

		public BaseClass(string a, Action callback)
		{
		}
	}
Comment 2 Marek Safar 2013-06-28 03:38:21 UTC
The code should fail to compile as it's incorrect. You are calling instance method from constructor which is not allowed. Changing Callback to be static should fix the issue.