2
0
Эх сурвалжийг харах

Properly make a copy during autoprop direct field access optimization

Brian Fiete 4 жил өмнө
parent
commit
981e56baad

+ 14 - 1
IDEHelper/Compiler/BfExprEvaluator.cpp

@@ -4832,6 +4832,8 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
 								auto result = LookupField(targetSrc, target, autoFieldName, BfLookupFieldFlag_IgnoreProtection);
 								auto result = LookupField(targetSrc, target, autoFieldName, BfLookupFieldFlag_IgnoreProtection);
 								if (result)
 								if (result)
 								{
 								{
+									bool needsCopy = true;
+									
 									if (!hasSetter)
 									if (!hasSetter)
 									{
 									{
 										if (((mModule->mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)) &&
 										if (((mModule->mCurMethodInstance->mMethodDef->mMethodType == BfMethodType_Ctor)) &&
@@ -4840,11 +4842,22 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
 											// Allow writing inside ctor
 											// Allow writing inside ctor
 										}
 										}
 										else
 										else
+										{
 											result.MakeReadOnly();
 											result.MakeReadOnly();
+											needsCopy = false;
+										}
 									}
 									}
+
+									if (needsCopy)
+									{
+										result = mModule->LoadValue(result);
+										result = mModule->MakeAddressable(result);
+										result = mModule->RemoveReadOnly(result);
+									}
+
 									mPropDef = NULL;
 									mPropDef = NULL;
 									mPropSrc = NULL;
 									mPropSrc = NULL;
-									mOrigPropTarget = NULL;									
+									mOrigPropTarget = NULL;
 									return result;
 									return result;
 								}
 								}
 							}
 							}