Beef icon indicating copy to clipboard operation
Beef copied to clipboard

Error while specializing method

Open disarray2077 opened this issue 1 year ago • 0 comments

I get the following error when trying to compile the code below:

ERROR: Binary operation for 'TryBeef.Program.Test2.anon<int, method reference TryBeef.Program.Main.anon(int x, int y)>(int i)' must result in 'T' from binary operation 'int * int'
  while specializing method 'TryBeef.Program.Test1<int, method reference TryBeef.Program.Test2.anon<int, method reference TryBeef.Program.Main.anon(int x, int y)>(int i)>(int x, method reference TryBeef.Program.Test2.anon<int, method reference TryBeef.Program.Main.anon(int x, int y)>(int i) body)' at line 12:3 in /Project/src/Program.bf
  body(x);
  ^^^^

The error only happens when Test2 uses a method reference, but it compiles fine if it creates a delegate.

Code:

using System;

namespace TryBeef;

class Program
{
	public static void Test1<T, TPred>(T x, TPred body)
		where TPred : delegate void(T)
		where T : operator T * T
	{
		body(x);
	}

	public static void Test2<T, TPred>(T x, T y, TPred body)
		where TPred : delegate void(T, T)
		where T : operator T * T
	{
		Test1(x * y, (i) => {
			body(x, y);
		});
	}


	public static void Main()
	{
		Test2(2, 2, (x, y) => {
			Console.WriteLine($"{x} {y}");
		});
	}
}

Online repro: https://trybeef.netlify.app/#/WiyfA8 Tested with: https://github.com/beefytech/Beef/commit/f1a275d6efabfb7b2e2004295bfba3c030d98cf5

disarray2077 avatar Apr 11 '24 19:04 disarray2077