diff --git a/IDEHelper/Compiler/BfExprEvaluator.cpp b/IDEHelper/Compiler/BfExprEvaluator.cpp index 555ea424..f92a2217 100644 --- a/IDEHelper/Compiler/BfExprEvaluator.cpp +++ b/IDEHelper/Compiler/BfExprEvaluator.cpp @@ -11625,7 +11625,10 @@ void BfExprEvaluator::Visit(BfInitializerExpression* initExpr) mModule->mBfIRBuilder->SetInsertPoint(initBlock); } - BfTypedValue initValue = GetResult(true); + BfTypedValue origInitValue = GetResult(true); + BfTypedValue initValue = origInitValue; + if ((initValue) && (initValue.mType->IsRef())) + initValue = mModule->RemoveRef(initValue, false); bool isFirstAdd = true; for (auto elementExpr : initExpr->mValues) @@ -11749,7 +11752,7 @@ void BfExprEvaluator::Visit(BfInitializerExpression* initExpr) mModule->mBfIRBuilder->SetInsertPoint(curBlock); } - mResult = initValue; + mResult = origInitValue; } void BfExprEvaluator::Visit(BfCollectionInitializerExpression* arrayInitExpr) diff --git a/IDEHelper/Compiler/BfModule.cpp b/IDEHelper/Compiler/BfModule.cpp index e8d6b1c6..5d5ce9e6 100644 --- a/IDEHelper/Compiler/BfModule.cpp +++ b/IDEHelper/Compiler/BfModule.cpp @@ -12944,7 +12944,7 @@ BfVariant BfModule::TypedValueToVariant(BfAstNode* refNode, const BfTypedValue& return variant; } -BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue) +BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue, bool makeInReadOnly) { if ((typedValue.mType != NULL) && (typedValue.mType->IsRef())) { @@ -12969,7 +12969,7 @@ BfTypedValue BfModule::RemoveRef(BfTypedValue typedValue) BF_ASSERT(typedValue.mValue.IsFake()); } - if (refType->mRefKind == BfRefType::RefKind_In) + if ((refType->mRefKind == BfRefType::RefKind_In) && (makeInReadOnly)) { if (typedValue.mKind == BfTypedValueKind_Addr) typedValue.mKind = BfTypedValueKind_ReadOnlyAddr; diff --git a/IDEHelper/Compiler/BfModule.h b/IDEHelper/Compiler/BfModule.h index 811b5cf3..f0bee551 100644 --- a/IDEHelper/Compiler/BfModule.h +++ b/IDEHelper/Compiler/BfModule.h @@ -1752,7 +1752,7 @@ public: void EmitDynamicCastCheck(const BfTypedValue& targetValue, BfType* targetType, BfIRBlock trueBlock, BfIRBlock falseBlock, bool nullSucceeds = false); void EmitDynamicCastCheck(BfTypedValue typedVal, BfType* type, bool allowNull); void CheckStaticAccess(BfTypeInstance* typeInstance); - BfTypedValue RemoveRef(BfTypedValue typedValue); + BfTypedValue RemoveRef(BfTypedValue typedValue, bool makeInReadOnly = true); BfTypedValue SanitizeAddr(BfTypedValue typedValue); BfTypedValue ToRef(BfTypedValue typedValue, BfRefType* refType = NULL); BfTypedValue LoadOrAggregateValue(BfTypedValue typedValue);