Skip to content

Commit cd592ed

Browse files
authored
fix #19193 (#19195) [backport:1.2]
1 parent 93c8427 commit cd592ed

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Diff for: compiler/cgen.nim

+8-2
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,14 @@ proc constructLoc(p: BProc, loc: var TLoc, isTemp = false) =
443443
if optSeqDestructors in p.config.globalOptions and skipTypes(typ, abstractInst + {tyStatic}).kind in {tyString, tySequence}:
444444
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
445445
elif not isComplexValueType(typ):
446-
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
447-
getTypeDesc(p.module, typ, mapTypeChooser(loc))])
446+
if containsGarbageCollectedRef(loc.t):
447+
var nilLoc: TLoc
448+
initLoc(nilLoc, locTemp, loc.lode, OnStack)
449+
nilLoc.r = rope("NIM_NIL")
450+
genRefAssign(p, loc, nilLoc)
451+
else:
452+
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
453+
getTypeDesc(p.module, typ, mapTypeChooser(loc))])
448454
else:
449455
if not isTemp or containsGarbageCollectedRef(loc.t):
450456
# don't use nimZeroMem for temporary values for performance if we can

0 commit comments

Comments
 (0)