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:
parent
40c404f329
commit
5d1a9e6873
4 changed files with 68 additions and 9 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
46
IDEHelper/Tests/src/Virtuals.bf
Normal file
46
IDEHelper/Tests/src/Virtuals.bf
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue