Skip to content

Commit 37d6cfb

Browse files
committed
liftdestructors: generate proper isNil check
1 parent 8f1463d commit 37d6cfb

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/sem/liftdestructors.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,16 @@ proc atomicClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
657657
of attachedAsgn:
658658
let yenv = genBuiltin(c, mAccessEnv, "accessEnv", y)
659659
yenv.typ = getSysType(c.g, c.info, tyPointer)
660+
var nilCheck = genBuiltin(c, mIsNil, "isNil", yenv)
661+
nilCheck.typ = cond.typ
662+
nilCheck = genBuiltin(c, mNot, "not", nilCheck)
663+
nilCheck.typ = cond.typ
660664
if isCyclic:
661-
body.add genIf(c, yenv, callCodegenProc(c.g, "nimIncRefCyclic", c.info, yenv, getCycleParam(c)))
665+
body.add genIf(c, nilCheck, callCodegenProc(c.g, "nimIncRefCyclic", c.info, yenv, getCycleParam(c)))
662666
body.add newAsgnStmt(x, y)
663667
body.add genIf(c, cond, actions)
664668
else:
665-
body.add genIf(c, yenv, callCodegenProc(c.g, "nimIncRef", c.info, yenv))
666-
669+
body.add genIf(c, nilCheck, callCodegenProc(c.g, "nimIncRef", c.info, yenv))
667670
body.add genIf(c, cond, actions)
668671
body.add newAsgnStmt(x, y)
669672
of attachedDestructor:

0 commit comments

Comments
 (0)