mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 20:12:21 +02:00
Fixed LoadProperty for struct pointers
This commit is contained in:
parent
ba0ff23e9d
commit
1aa99da714
2 changed files with 46 additions and 8 deletions
|
@ -4798,6 +4798,13 @@ BfTypedValue BfExprEvaluator::TryArrowLookup(BfTypedValue typedValue, BfTokenNod
|
|||
|
||||
BfTypedValue BfExprEvaluator::LoadProperty(BfAstNode* targetSrc, BfTypedValue target, BfTypeInstance* typeInstance, BfPropertyDef* prop, BfLookupFieldFlags flags, BfCheckedKind checkedKind, bool isInlined)
|
||||
{
|
||||
BfTypedValue origTarget = target;
|
||||
if (target.mType->IsStructPtr())
|
||||
{
|
||||
target = mModule->LoadValue(target);
|
||||
target = BfTypedValue(target.mValue, target.mType->GetUnderlyingType(), target.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
|
||||
}
|
||||
|
||||
if ((flags & BfLookupFieldFlag_IsAnonymous) == 0)
|
||||
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
||||
|
||||
|
@ -4855,16 +4862,21 @@ BfTypedValue BfExprEvaluator::LoadProperty(BfAstNode* targetSrc, BfTypedValue ta
|
|||
else
|
||||
mPropTarget = target;
|
||||
|
||||
if (mPropTarget.mType->IsStructPtr())
|
||||
{
|
||||
mPropTarget = mModule->LoadValue(mPropTarget);
|
||||
mPropTarget = BfTypedValue(mPropTarget.mValue, mPropTarget.mType->GetUnderlyingType(), mPropTarget.IsReadOnly() ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
|
||||
}
|
||||
|
||||
mOrigPropTarget = mPropTarget;
|
||||
if (prop->mIsStatic)
|
||||
mOrigPropTarget = target;
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (mPropTarget)
|
||||
{
|
||||
auto propTargetTypeInst = mPropTarget.mType->ToTypeInstance();
|
||||
if (propTargetTypeInst != NULL)
|
||||
{
|
||||
BF_ASSERT(prop->mDeclaringType->mFullNameEx == propTargetTypeInst->mTypeDef->mFullNameEx);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((flags & BfLookupFieldFlag_IsAnonymous) == 0)
|
||||
{
|
||||
auto autoComplete = GetAutoComplete();
|
||||
|
@ -19167,6 +19179,8 @@ BfModuleMethodInstance BfExprEvaluator::GetPropertyMethodInstance(BfMethodDef* m
|
|||
return BfModuleMethodInstance();
|
||||
}
|
||||
|
||||
BF_ASSERT(propTypeInst->mTypeDef->mFullNameEx == methodDef->mDeclaringType->mFullNameEx);
|
||||
|
||||
return mModule->GetMethodInstance(propTypeInst, methodDef, BfTypeVector(), mPropGetMethodFlags);
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,16 @@ namespace Tests
|
|||
}
|
||||
}
|
||||
|
||||
struct StructD
|
||||
{
|
||||
public int Val => 123;
|
||||
}
|
||||
|
||||
struct StructE : StructD
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class ClassB
|
||||
{
|
||||
public StructA B { get; set; }
|
||||
|
@ -131,6 +141,16 @@ namespace Tests
|
|||
return val.Val;
|
||||
}
|
||||
|
||||
static void TestVal(int val)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void TestVal(float val)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -177,6 +197,10 @@ namespace Tests
|
|||
int ap2 = StructA.sAutoProp++;
|
||||
Test.Assert(ap2 == 3);
|
||||
Test.Assert(StructA.sAutoProp == 4);
|
||||
|
||||
StructE* se = scope .();
|
||||
StructE*[2] seArr = .(se, se);
|
||||
Test.Assert((seArr[0].Val + seArr[1].Val) == 123*2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue