mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-09 03:52:19 +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 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)
|
if ((flags & BfLookupFieldFlag_IsAnonymous) == 0)
|
||||||
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
||||||
|
|
||||||
|
@ -4832,7 +4839,7 @@ BfTypedValue BfExprEvaluator::LoadProperty(BfAstNode* targetSrc, BfTypedValue ta
|
||||||
mModule->Fail(StrFormat("Property '%s.%s' cannot be accessed with an instance reference; qualify it with a type name instead",
|
mModule->Fail(StrFormat("Property '%s.%s' cannot be accessed with an instance reference; qualify it with a type name instead",
|
||||||
mModule->TypeToString(typeInstance).c_str(), mPropDef->mName.c_str()), targetSrc);
|
mModule->TypeToString(typeInstance).c_str(), mPropDef->mName.c_str()), targetSrc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isBaseLookup = (target.mType) && (typeInstance != target.mType);
|
bool isBaseLookup = (target.mType) && (typeInstance != target.mType);
|
||||||
if ((isBaseLookup) && (target.mType->IsWrappableType()))
|
if ((isBaseLookup) && (target.mType->IsWrappableType()))
|
||||||
|
@ -4853,18 +4860,23 @@ BfTypedValue BfExprEvaluator::LoadProperty(BfAstNode* targetSrc, BfTypedValue ta
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
mPropTarget = target;
|
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;
|
mOrigPropTarget = mPropTarget;
|
||||||
if (prop->mIsStatic)
|
if (prop->mIsStatic)
|
||||||
mOrigPropTarget = target;
|
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)
|
if ((flags & BfLookupFieldFlag_IsAnonymous) == 0)
|
||||||
{
|
{
|
||||||
auto autoComplete = GetAutoComplete();
|
auto autoComplete = GetAutoComplete();
|
||||||
|
@ -19167,6 +19179,8 @@ BfModuleMethodInstance BfExprEvaluator::GetPropertyMethodInstance(BfMethodDef* m
|
||||||
return BfModuleMethodInstance();
|
return BfModuleMethodInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BF_ASSERT(propTypeInst->mTypeDef->mFullNameEx == methodDef->mDeclaringType->mFullNameEx);
|
||||||
|
|
||||||
return mModule->GetMethodInstance(propTypeInst, methodDef, BfTypeVector(), mPropGetMethodFlags);
|
return mModule->GetMethodInstance(propTypeInst, methodDef, BfTypeVector(), mPropGetMethodFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,16 @@ namespace Tests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct StructD
|
||||||
|
{
|
||||||
|
public int Val => 123;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct StructE : StructD
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class ClassB
|
class ClassB
|
||||||
{
|
{
|
||||||
public StructA B { get; set; }
|
public StructA B { get; set; }
|
||||||
|
@ -131,6 +141,16 @@ namespace Tests
|
||||||
return val.Val;
|
return val.Val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void TestVal(int val)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestVal(float val)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public static void TestBasics()
|
public static void TestBasics()
|
||||||
{
|
{
|
||||||
|
@ -177,6 +197,10 @@ namespace Tests
|
||||||
int ap2 = StructA.sAutoProp++;
|
int ap2 = StructA.sAutoProp++;
|
||||||
Test.Assert(ap2 == 3);
|
Test.Assert(ap2 == 3);
|
||||||
Test.Assert(StructA.sAutoProp == 4);
|
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