1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 12:02:21 +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(); auto target = mModule->GetThis();
target.mType = type; target.mType = type;
mResult = LookupField(nameNode->mRight, target, fieldName); mResult = LookupField(nameNode->mRight, target, fieldName);
if (mPropDef != NULL) if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
{
mPropDefBypassVirtual = true; mPropDefBypassVirtual = true;
}
return; return;
} }
} }
@ -7906,11 +7904,9 @@ void BfExprEvaluator::LookupQualifiedName(BfQualifiedNameNode* nameNode, bool ig
if (mPropDef != NULL) if (mPropDef != NULL)
{ {
mOrigPropTarget = origResult; mOrigPropTarget = origResult;
if ((CheckIsBase(nameNode->mLeft)) || (wasBaseLookup)) if (((CheckIsBase(nameNode->mLeft)) || (wasBaseLookup)) && (mPropDef->IsVirtual()))
{
mPropDefBypassVirtual = true; mPropDefBypassVirtual = true;
} }
}
if ((mResult) || (mPropDef != NULL)) if ((mResult) || (mPropDef != NULL))
return; return;
@ -7946,10 +7942,8 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
auto target = mModule->GetThis(); auto target = mModule->GetThis();
target.mType = type; target.mType = type;
mResult = LookupField(nameRight, target, fieldName); mResult = LookupField(nameRight, target, fieldName);
if (mPropDef != NULL) if ((mPropDef != NULL) && (mPropDef->IsVirtual()))
{
mPropDefBypassVirtual = true; mPropDefBypassVirtual = true;
}
return; return;
} }
} }
@ -8119,6 +8113,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
mOrigPropTarget = origResult; mOrigPropTarget = origResult;
if ((CheckIsBase(nameLeft)) || (wasBaseLookup)) if ((CheckIsBase(nameLeft)) || (wasBaseLookup))
{ {
if (mPropDef->IsVirtual())
mPropDefBypassVirtual = true; mPropDefBypassVirtual = true;
} }
} }

View file

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

View file

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

View file

@ -47,6 +47,8 @@ namespace Tests
class ClassB class ClassB
{ {
public StructA B { get; set; } public StructA B { get; set; }
public int IVal { get => 1; }
public virtual int IVal2 { get => 2; }
int mZ = 9; 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] [Test]
public static void TestBasics() public static void TestBasics()
{ {
@ -71,6 +79,13 @@ namespace Tests
cb.B = .(333); cb.B = .(333);
sa = cb.B; sa = cb.B;
Test.Assert(sa.mA == 333); 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);
} }
} }
} }