Skip to content

Commit d7b1f0a

Browse files
authored
fix(js): nonvar destructor was disallowed; closes #24914 (#24915)
1 parent eea4ce0 commit d7b1f0a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

compiler/semstmts.nim

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,13 +2153,17 @@ proc bindDupHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) =
21532153
proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) =
21542154
let t = s.typ
21552155
var noError = false
2156+
template notRefc: bool =
2157+
# fixes refc with non-var destructor; cancel warnings (#23156)
2158+
c.config.backend == backendJs or
2159+
c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}
21562160
let cond = case op
21572161
of attachedWasMoved:
21582162
t.len == 2 and t.returnType == nil and t.firstParamType.kind == tyVar
21592163
of attachedTrace:
21602164
t.len == 3 and t.returnType == nil and t.firstParamType.kind == tyVar and t[2].kind == tyPointer
21612165
of attachedDestructor:
2162-
if c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}:
2166+
if notRefc:
21632167
t.len == 2 and t.returnType == nil
21642168
else:
21652169
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) =
21922196
localError(c.config, n.info, errGenerated,
21932197
"signature for '=trace' must be proc[T: object](x: var T; env: pointer)")
21942198
of attachedDestructor:
2195-
if c.config.selectedGC in {gcArc, gcAtomicArc, gcOrc}:
2199+
if notRefc:
21962200
localError(c.config, n.info, errGenerated,
21972201
"signature for '=destroy' must be proc[T: object](x: var T) or proc[T: object](x: T)")
21982202
else:

0 commit comments

Comments
 (0)