mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +02:00
Fixed 'base' lookup for properties
This commit is contained in:
parent
473246fa51
commit
f9bed24c00
4 changed files with 30 additions and 12 deletions
|
@ -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)
|
||||
{
|
||||
mPropDefBypassVirtual = true;
|
||||
}
|
||||
if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
|
||||
mPropDefBypassVirtual = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -7906,10 +7904,8 @@ 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)
|
||||
{
|
||||
mPropDefBypassVirtual = true;
|
||||
}
|
||||
if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
|
||||
mPropDefBypassVirtual = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -8119,7 +8113,8 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
|||
mOrigPropTarget = origResult;
|
||||
if ((CheckIsBase(nameLeft)) || (wasBaseLookup))
|
||||
{
|
||||
mPropDefBypassVirtual = true;
|
||||
if (mPropDef->IsVirtual())
|
||||
mPropDefBypassVirtual = true;
|
||||
}
|
||||
}
|
||||
if ((mResult) || (mPropDef != NULL))
|
||||
|
|
|
@ -381,6 +381,13 @@ BfSizedAtomComposite::~BfSizedAtomComposite()
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool BfPropertyDef::IsVirtual()
|
||||
{
|
||||
if (((BfPropertyDeclaration*)mFieldDeclaration)->mVirtualSpecifier)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BfPropertyDef::HasExplicitInterface()
|
||||
{
|
||||
for (auto methodDef : mMethods)
|
||||
|
|
|
@ -575,6 +575,7 @@ public:
|
|||
mNextWithSameName = NULL;
|
||||
}
|
||||
|
||||
bool IsVirtual();
|
||||
bool HasExplicitInterface();
|
||||
BfAstNode* GetRefNode();
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue