Beef icon indicating copy to clipboard operation
Beef copied to clipboard

Can not use function for valueless generic constraint

Open mailgerigk opened this issue 6 months ago • 0 comments

Current

This code does not compile.

namespace test;

class Program
{
	static T Max<T, TFunc>(T lhs, T rhs, TFunc func) where TFunc : function int(T lhs, T rhs)
	{
		return (func(lhs, rhs) >= 0) ? lhs : rhs;
	}

	static int Cmp(float lhs, float rhs)
	{
		return lhs <=> rhs;
	}

	float max = Max(5.4f, 1.2f, => Cmp); 
}

Generic argument 'TFunc', declared to be 'method reference test.Program.Cmp(float lhs, float rhs)' for 'test.Program.Max<float, method reference test.Program.Cmp(float lhs, float rhs)>(float lhs, float rhs, method reference test.Program.Cmp(float lhs, float rhs) func)', must derive from 'function int(float lhs, float rhs)'

Expected

This code should compile.

mailgerigk avatar Jun 23 '25 07:06 mailgerigk