Skip to content

Commit 5a14e3e

Browse files
zerbinasaem
andauthored
liftdestructors: generate proper isNil check (nim-works#1630)
## Summary Fix an internal issue with type-bound operator lifting for closure types. ## Details Instead of a proper `isNil` check, generation of the "not nil" check for closure environments used the pointer expression itself as the condition expression of an `if`. Since the expression was translated as is and a pointer value is valid in an `if` condition position in C, this worked, but it's not correct according to NimSkull's type system. A proper "not nil" check is generated now. Co-authored-by: Saem Ghani <saemghani+github@gmail.com>
1 parent 07959b7 commit 5a14e3e

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)