1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

Fixed 'base' lookup for properties

This commit is contained in:
Brian Fiete 2020-08-03 06:09:45 -07:00
parent 473246fa51
commit f9bed24c00
4 changed files with 30 additions and 12 deletions

View file

@ -7749,10 +7749,8 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
auto target = mModule->GetThis();
target.mType = type;
mResult = LookupField(nameNode->mRight, target, fieldName);
if (mPropDef != NULL)
{
if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
mPropDefBypassVirtual = true;
}
return;
}
}
@ -7906,11 +7904,9 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
if (mPropDef != NULL)
{
mOrigPropTarget = origResult;
if ((CheckIsBase(nameNode->mLeft)) || (wasBaseLookup))
{
if (((CheckIsBase(nameNode->mLeft)) || (wasBaseLookup)) && (mPropDef->IsVirtual()))
mPropDefBypassVirtual = true;
}
}
if ((mResult) || (mPropDef != NULL))
return;
@ -7946,10 +7942,8 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
auto target = mModule->GetThis();
target.mType = type;
mResult = LookupField(nameRight, target, fieldName);
if (mPropDef != NULL)
{
if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
mPropDefBypassVirtual = true;
}
return;
}
}
@ -8119,6 +8113,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
mOrigPropTarget = origResult;
if ((CheckIsBase(nameLeft)) || (wasBaseLookup))
{
if (mPropDef->IsVirtual())
mPropDefBypassVirtual = true;
}
}

View file

@ -381,6 +381,13 @@ BfSizedAtomComposite::~BfSizedAtomComposite()
//////////////////////////////////////////////////////////////////////////
bool BfPropertyDef::IsVirtual()
{
if (((BfPropertyDeclaration*)mFieldDeclaration)->mVirtualSpecifier)
return true;
return false;
}
bool BfPropertyDef::HasExplicitInterface()
{
for (auto methodDef : mMethods)

View file

@ -575,6 +575,7 @@ public:
mNextWithSameName = NULL;
}
bool IsVirtual();
bool HasExplicitInterface();
BfAstNode* GetRefNode();
};

View file

@ -47,6 +47,8 @@ namespace Tests
class ClassB
{
public StructA B { get; set; }
public int IVal { get => 1; }
public virtual int IVal2 { get => 2; }
int mZ = 9;
@ -55,6 +57,12 @@ namespace Tests
}
}
class ClassC : ClassB
{
public new int IVal { get => base.IVal + 100; }
public override int IVal2 { get => base.IVal2 + 100; }
}
[Test]
public static void TestBasics()
{
@ -71,6 +79,13 @@ namespace Tests
cb.B = .(333);
sa = cb.B;
Test.Assert(sa.mA == 333);
ClassC cc = scope .();
Test.Assert(cc.IVal == 101);
Test.Assert(cc.IVal2 == 102);
ClassB cb2 = cc;
Test.Assert(cb2.IVal == 1);
Test.Assert(cb2.IVal2 == 102);
}
}
}