The fix adds a guard: when d.k == locExpr and the destination type differs from the constructor type (inheritance/subtyping), a temporary is still used so that genAssignment can perform the proper type-tag and slicing checks.

This commit is contained in:
ringabout
2026-04-07 16:00:04 +08:00
parent 6df3fd8d88
commit 3cbda905e5

View File

@@ -1893,6 +1893,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
var useTemp =
isRef or
(d.k notin {locTemp,locLocalVar,locGlobalVar,locParam,locField,locExpr}) or
(d.k == locExpr and d.lode.typ != nil and not sameType(d.lode.typ.skipTypes(abstractInst), t)) or
(isPartOf(d.lode, e) != arNo)
var tmp: TLoc = default(TLoc)