diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 941327341e..ea2a468219 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1892,7 +1892,8 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = # check if we need to construct the object in a temporary var useTemp = isRef or - (d.k notin {locTemp,locLocalVar,locGlobalVar,locParam,locField}) or + (d.k notin {locTemp,locLocalVar,locGlobalVar,locParam,locField} and + d.storage != OnHeap) or (isPartOf(d.lode, e) != arNo) var tmp: TLoc = default(TLoc)