@@ -429,9 +429,7 @@ proc atomicRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
429429 body.add genIf (c, cond, actions)
430430 body.add newAsgnStmt (x, y)
431431 of attachedDestructor:
432- when false :
433- # XXX investigate if this is necessary:
434- actions.add newAsgnStmt (x, newNodeIT (nkNilLit, body.info, t))
432+ actions.add newAsgnStmt (x, newNodeIT (nkNilLit, body.info, t))
435433 body.add genIf (c, cond, actions)
436434 of attachedDeepCopy: assert (false , " cannot happen" )
437435 of attachedTrace:
@@ -480,9 +478,7 @@ proc atomicClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
480478 body.add genIf (c, cond, actions)
481479 body.add newAsgnStmt (x, y)
482480 of attachedDestructor:
483- when false :
484- # XXX investigate if this is necessary:
485- actions.add newAsgnStmt (xenv, newNodeIT (nkNilLit, body.info, xenv.typ))
481+ actions.add newAsgnStmt (xenv, newNodeIT (nkNilLit, body.info, xenv.typ))
486482 body.add genIf (c, cond, actions)
487483 of attachedDeepCopy: assert (false , " cannot happen" )
488484 of attachedTrace:
@@ -510,7 +506,10 @@ proc weakrefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
510506 of attachedDestructor:
511507 # it's better to prepend the destruction of weak refs in order to
512508 # prevent wrong "dangling refs exist" problems:
513- let des = genIf (c, x, callCodegenProc (c.g, " nimDecWeakRef" , c.info, x))
509+ var actions = newNodeI (nkStmtList, c.info)
510+ actions.add callCodegenProc (c.g, " nimDecWeakRef" , c.info, x)
511+ actions.add newAsgnStmt (x, newNodeIT (nkNilLit, body.info, t))
512+ let des = genIf (c, x, actions)
514513 if body.len == 0 :
515514 body.add des
516515 else :
@@ -537,6 +536,7 @@ proc ownedRefOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
537536 body.add genIf (c, x, actions)
538537 body.add newAsgnStmt (x, y)
539538 of attachedDestructor:
539+ actions.add newAsgnStmt (x, newNodeIT (nkNilLit, body.info, t))
540540 body.add genIf (c, x, actions)
541541 of attachedDeepCopy: assert (false , " cannot happen" )
542542 of attachedTrace, attachedDispose: discard
@@ -567,7 +567,10 @@ proc closureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
567567 body.add genIf (c, xx, callCodegenProc (c.g, " nimDecWeakRef" , c.info, xx))
568568 body.add newAsgnStmt (x, y)
569569 of attachedDestructor:
570- let des = genIf (c, xx, callCodegenProc (c.g, " nimDecWeakRef" , c.info, xx))
570+ var actions = newNodeI (nkStmtList, c.info)
571+ actions.add callCodegenProc (c.g, " nimDecWeakRef" , c.info, xx)
572+ actions.add newAsgnStmt (xx, newNodeIT (nkNilLit, body.info, xx.typ))
573+ let des = genIf (c, xx, actions)
571574 if body.len == 0 :
572575 body.add des
573576 else :
@@ -586,6 +589,7 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
586589 body.add genIf (c, xx, actions)
587590 body.add newAsgnStmt (x, y)
588591 of attachedDestructor:
592+ actions.add newAsgnStmt (xx, newNodeIT (nkNilLit, body.info, xx.typ))
589593 body.add genIf (c, xx, actions)
590594 of attachedDeepCopy: assert (false , " cannot happen" )
591595 of attachedTrace, attachedDispose: discard
0 commit comments