Beef icon indicating copy to clipboard operation
Beef copied to clipboard

[Enhancement] Allow explict lambda parameter types

Open disarray2077 opened this issue 4 years ago • 1 comments

Example:

(String self) => { return self; }

Otherwise, it's impossible to make this compile without the casts:

		[Comptime]
		public static void EmitCode<F>()
			where F : var
		{
			var invokeMethod = typeof(F).GetMethod("Invoke").Get();
			Debug.WriteLine("CompTime");
			Debug.WriteLine(invokeMethod.ReturnType.GetFullName(.. scope .()));
			Debug.WriteLine(invokeMethod.GetParamType(0).GetFullName(.. scope .()));
			Debug.WriteLine(invokeMethod.GetParamType(1).GetFullName(.. scope .()));
		}

		public static void Test1<F>(F func)
		{
			EmitCode<F>();
		}

		public static int Main(String[] args)
		{
			Test1(/*(delegate String(String, uint8))*/ (new (a, b) => { return a; }));
			Test1(/*(function String(String, uint8))*/ ((a, b) => { return a; }));
			return 0;
		}

disarray2077 avatar Nov 05 '21 23:11 disarray2077

I just saw this: https://devblogs.microsoft.com/dotnet/welcome-to-csharp-10/ :

Starting with C# 10, however, if a lambda does not have such a “target type” we will try to compute one for you:

var parse = (string s) => int.Parse(s);

So I guess they beat us to that one.

bfiete avatar Nov 08 '21 20:11 bfiete