diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index b5990161ebc1a..6f2ddd95a6317 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -526,7 +526,9 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = selfPtr.add transFormedSym.ast[bodyPos][1] selfPtr.typ = selfSymbolType transFormedSym.ast[bodyPos][1] = c.semExpr(c, selfPtr) - bindTypeHook(c, transFormedSym, n, attachedDestructor) + # TODO: suppress var destructor warnings; if newFinalizer is not + # TODO: deprecated, try to implement plain T destructor + bindTypeHook(c, transFormedSym, n, attachedDestructor, suppressVarDestructorWarning = true) result = addDefaultFieldForNew(c, n) proc semPrivateAccess(c: PContext, n: PNode): PNode = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 2df1c42b3d1e3..a4de874ba9df8 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1904,7 +1904,7 @@ proc bindDupHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = incl(s.flags, sfUsed) incl(s.flags, sfOverridden) -proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = +proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp; suppressVarDestructorWarning = false) = let t = s.typ var noError = false let cond = case op @@ -1923,7 +1923,7 @@ proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = elif obj.kind == tyGenericInvocation: obj = obj[0] else: break if obj.kind in {tyObject, tyDistinct, tySequence, tyString}: - if op == attachedDestructor and t[1].kind == tyVar: + if (not suppressVarDestructorWarning) and op == attachedDestructor and t[1].kind == tyVar: message(c.config, n.info, warnDeprecated, "A custom '=destroy' hook which takes a 'var T' parameter is deprecated; it should take a 'T' parameter") obj = canonType(c, obj) let ao = getAttachedOp(c.graph, obj, op)