mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Added proper support for explicit 'this' in functions
This commit is contained in:
parent
4a08a9702e
commit
7f726ef9ba
8 changed files with 438 additions and 142 deletions
59
IDEHelper/Tests/src/Functions.bf
Normal file
59
IDEHelper/Tests/src/Functions.bf
Normal file
|
@ -0,0 +1,59 @@
|
|||
#pragma warning disable 168
|
||||
|
||||
using System;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
class Functions
|
||||
{
|
||||
class ClassA
|
||||
{
|
||||
int mA = 123;
|
||||
|
||||
public int GetA(float f)
|
||||
{
|
||||
return mA + (int)f;
|
||||
}
|
||||
|
||||
public int GetT<T>(T val) where T : var
|
||||
{
|
||||
return mA + (int)val;
|
||||
}
|
||||
}
|
||||
|
||||
struct StructA
|
||||
{
|
||||
int mA = 123;
|
||||
int mB = 234;
|
||||
|
||||
public int GetA(float f)
|
||||
{
|
||||
return mA + mB*100 + (int)f;
|
||||
}
|
||||
|
||||
public int GetA2(float f) mut
|
||||
{
|
||||
return mA + mB*100 + (int)f;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
ClassA ca = scope .();
|
||||
StructA sa = .();
|
||||
|
||||
function int (ClassA this, float f) func0 = => ca.GetA;
|
||||
function int (ClassA this, float) func0b = func0;
|
||||
Test.Assert(func0(ca, 100.0f) == 223);
|
||||
func0 = => ca.GetT<float>;
|
||||
Test.Assert(func0(ca, 100.0f) == 223);
|
||||
|
||||
function int (StructA this, float f) func1 = => sa.GetA;
|
||||
Test.Assert(func1(sa, 100.0f) == 23623);
|
||||
|
||||
function int (mut StructA this, float f) func2 = => sa.GetA2;
|
||||
Test.Assert(func2(mut sa, 100.0f) == 23623);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue