mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 04:52:21 +02:00
Fixed erroneous autoprop optimization when getter or setter has a body
This commit is contained in:
parent
78c39c5f87
commit
91897f8cb3
1 changed files with 34 additions and 23 deletions
|
@ -4871,34 +4871,45 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
{
|
{
|
||||||
if ((curCheckType->mTypeDef->HasAutoProperty(propertyDeclaration)) && (propertyDeclaration->mVirtualSpecifier == NULL))
|
if ((curCheckType->mTypeDef->HasAutoProperty(propertyDeclaration)) && (propertyDeclaration->mVirtualSpecifier == NULL))
|
||||||
{
|
{
|
||||||
bool hasSetter = GetPropertyMethodDef(mPropDef, BfMethodType_PropertySetter, BfCheckedKind_NotSet, mPropTarget) != NULL;
|
BfMethodDef* getter = GetPropertyMethodDef(mPropDef, BfMethodType_PropertySetter, BfCheckedKind_NotSet, mPropTarget);
|
||||||
auto autoFieldName = curCheckType->mTypeDef->GetAutoPropertyName(propertyDeclaration);
|
BfMethodDef* setter = GetPropertyMethodDef(mPropDef, BfMethodType_PropertySetter, BfCheckedKind_NotSet, mPropTarget);
|
||||||
auto result = LookupField(targetSrc, target, autoFieldName, (BfLookupFieldFlags)(BfLookupFieldFlag_IgnoreProtection | BfLookupFieldFlag_IsImplicitThis));
|
|
||||||
if (result)
|
bool optAllowed = true;
|
||||||
|
if ((getter != NULL) && (getter->mBody != NULL))
|
||||||
|
optAllowed = false;
|
||||||
|
if ((setter != NULL) && (setter->mBody != NULL))
|
||||||
|
optAllowed = false;
|
||||||
|
|
||||||
|
if (optAllowed)
|
||||||
{
|
{
|
||||||
bool needsCopy = true;
|
auto autoFieldName = curCheckType->mTypeDef->GetAutoPropertyName(propertyDeclaration);
|
||||||
|
auto result = LookupField(targetSrc, target, autoFieldName, (BfLookupFieldFlags)(BfLookupFieldFlag_IgnoreProtection | BfLookupFieldFlag_IsImplicitThis));
|
||||||
if (!hasSetter)
|
if (result)
|
||||||
{
|
{
|
||||||
if (((mModule->mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)) &&
|
bool needsCopy = true;
|
||||||
(startCheckType == mModule->mCurTypeInstance))
|
|
||||||
|
if (setter == NULL)
|
||||||
{
|
{
|
||||||
// Allow writing inside ctor
|
if (((mModule->mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)) &&
|
||||||
}
|
(startCheckType == mModule->mCurTypeInstance))
|
||||||
else
|
{
|
||||||
{
|
// Allow writing inside ctor
|
||||||
result.MakeReadOnly();
|
}
|
||||||
needsCopy = false;
|
else
|
||||||
|
{
|
||||||
|
result.MakeReadOnly();
|
||||||
|
needsCopy = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.mKind == BfTypedValueKind_Addr)
|
||||||
|
result.mKind = BfTypedValueKind_CopyOnMutateAddr;
|
||||||
|
|
||||||
|
mPropDef = NULL;
|
||||||
|
mPropSrc = NULL;
|
||||||
|
mOrigPropTarget = NULL;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.mKind == BfTypedValueKind_Addr)
|
|
||||||
result.mKind = BfTypedValueKind_CopyOnMutateAddr;
|
|
||||||
|
|
||||||
mPropDef = NULL;
|
|
||||||
mPropSrc = NULL;
|
|
||||||
mOrigPropTarget = NULL;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue