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

Improvements to auto-impl properties

This commit is contained in:
Brian Fiete 2022-03-01 09:49:02 -08:00
parent 36e0a3a375
commit 06f4eb9576
8 changed files with 113 additions and 61 deletions

View file

@ -20710,6 +20710,9 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
}
else if (methodDef->mMethodType == BfMethodType_PropertyGetter)
{
if ((methodInstance->mReturnType->IsRef()) && (!methodDef->mIsMutating))
Fail("Auto-implemented ref property getters must declare 'mut'", methodInstance->mMethodDef->GetRefNode());
if (methodInstance->mReturnType->IsValuelessType())
{
mBfIRBuilder->CreateRetVoid();
@ -20736,8 +20739,14 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup,
lookupValue = BfTypedValue(mBfIRBuilder->CreateInBoundsGEP(GetThis().mValue, 0, fieldInstance->mDataIdx), fieldInstance->mResolvedType, true);
else
lookupValue = ExtractValue(GetThis(), fieldInstance, fieldInstance->mDataIdx);
if (!methodInstance->mReturnType->IsRef())
if (methodInstance->mReturnType->IsRef())
{
if ((!lookupValue.IsAddr()) && (!lookupValue.mType->IsValuelessType()))
lookupValue = MakeAddressable(lookupValue);
}
else
lookupValue = LoadOrAggregateValue(lookupValue);
CreateReturn(lookupValue.mValue);
EmitLifetimeEnds(&mCurMethodState->mHeadScope);
}