1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-07 16:56:00 +02:00

Fixed virtuals defaults issue, added virtuals test

This commit is contained in:
Brian Fiete 2020-02-21 06:08:59 -08:00
parent 40c404f329
commit 5d1a9e6873
4 changed files with 68 additions and 9 deletions

View file

@ -4289,9 +4289,19 @@ BfTypedValue BfExprEvaluator::CreateCall(BfMethodInstance* methodInstance, BfIRV
}
if (methodInstance->mVirtualTableIdx != -1)
{
{
if ((!bypassVirtual) && (mDeferCallRef == NULL))
{
if ((methodDef->mIsOverride) && (mModule->mCurMethodInstance->mIsReified))
{
// Ensure that declaring method gets referenced
auto typeInstance = methodInstance->GetOwner();
auto& vEntry = typeInstance->mVirtualMethodTable[methodInstance->mVirtualTableIdx];
BfMethodInstance* declaringMethodInstance = vEntry.mDeclaringMethod;
if ((declaringMethodInstance->mMethodInstanceGroup->mOnDemandKind < BfMethodOnDemandKind_InWorkList) || (!methodInstance->mIsReified))
mModule->GetMethodInstance(declaringMethodInstance);
}
auto funcType = mModule->mBfIRBuilder->MapMethod(methodInstance);
auto funcPtrType1 = mModule->mBfIRBuilder->GetPointerTo(funcType);
auto funcPtrType2 = mModule->mBfIRBuilder->GetPointerTo(funcPtrType1);

View file

@ -101,7 +101,9 @@ namespace Tests
static void TestA()
{
ClassA ca = scope ClassA();
ClassA2 ca2 = scope ClassA2();
Test.Assert(ca2.GetA(9) == 2009);
int methodIdx = 0;

View file

@ -0,0 +1,46 @@
#pragma warning disable 168
using System;
namespace Tests
{
class Virtuals
{
class ClassA
{
public virtual int Method0(int a = 111)
{
return a;
}
}
class ClassB : ClassA
{
public override int Method0(int a = 222)
{
return a + 1000;
}
}
class ClassC : ClassB
{
public override int Method0(int a)
{
return a + 2000;
}
}
[Test]
public static void TestBasics()
{
ClassA ca = scope ClassA();
Test.Assert(ca.Method0() == 111);
ClassB cb = scope ClassB();
Test.Assert(cb.Method0() == 1222);
cb = scope ClassC();
Test.Assert(cb.Method0() == 2222);
}
}
}