Skip to content

Commit f8047c3

Browse files
Menduistnarimiran
authored andcommitted
fix #19193 (#19195) [backport:1.2]
(cherry picked from commit cd592ed)
1 parent cfb6ebc commit f8047c3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/cgen.nim

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,14 @@ proc constructLoc(p: BProc, loc: var TLoc, isTemp = false) =
439439
if optSeqDestructors in p.config.globalOptions and skipTypes(typ, abstractInst + {tyStatic}).kind in {tyString, tySequence}:
440440
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
441441
elif not isComplexValueType(typ):
442-
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
443-
getTypeDesc(p.module, typ, mapTypeChooser(loc))])
442+
if containsGarbageCollectedRef(loc.t):
443+
var nilLoc: TLoc
444+
initLoc(nilLoc, locTemp, loc.lode, OnStack)
445+
nilLoc.r = rope("NIM_NIL")
446+
genRefAssign(p, loc, nilLoc)
447+
else:
448+
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
449+
getTypeDesc(p.module, typ, mapTypeChooser(loc))])
444450
else:
445451
if not isTemp or containsGarbageCollectedRef(loc.t):
446452
# don't use nimZeroMem for temporary values for performance if we can

0 commit comments

Comments
 (0)