From d7b1f0a99ab9acff13d1accbfeedc2345f9a19d5 Mon Sep 17 00:00:00 2001 From: lit Date: Tue, 29 Apr 2025 12:45:20 +0800 Subject: [PATCH] fix(js): nonvar destructor was disallowed; closes #24914 (#24915) --- compiler/semstmts.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 01307cc516..7039062306 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -2153,13 +2153,17 @@ proc bindDupHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = let t = s.typ var noError = false + template notRefc: bool = + # fixes refc with non-var destructor; cancel warnings (#23156) + c.config.backend == backendJs or + c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc} let cond = case op of attachedWasMoved: t.len == 2 and t.returnType == nil and t.firstParamType.kind == tyVar of attachedTrace: t.len == 3 and t.returnType == nil and t.firstParamType.kind == tyVar and t[2].kind == tyPointer of attachedDestructor: - if c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}: + if notRefc: t.len == 2 and t.returnType == nil else: t.len == 2 and t.returnType == nil and t.firstParamType.kind == tyVar @@ -2192,7 +2196,7 @@ proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = localError(c.config, n.info, errGenerated, "signature for '=trace' must be proc[T: object](x: var T; env: pointer)") of attachedDestructor: - if c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}: + if notRefc: localError(c.config, n.info, errGenerated, "signature for '=destroy' must be proc[T: object](x: var T) or proc[T: object](x: T)") else: