diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index c25f089fde0aa..eac2323aa933a 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -1069,7 +1069,7 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp let src = newSym(skParam, getIdent(g.cache, if kind == attachedTrace: "env" else: "src"), idgen, result, info) - if kind == attachedDestructor and typ.kind == tyRef: + if kind == attachedDestructor and typ.kind in {tyRef, tyString, tySequence} and g.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}: dest.typ = typ else: dest.typ = makeVarType(typ.owner, typ, idgen) @@ -1196,7 +1196,7 @@ proc patchBody(g: ModuleGraph; c: PContext; n: PNode; info: TLineInfo; idgen: Id if op != nil: if op.ast.isGenericRoutine: internalError(g.config, info, "resolved destructor is generic") - if op.magic == mDestroy: + if op.magic == mDestroy and t.kind != tyString: internalError(g.config, info, "patching mDestroy with mDestroy?") n[0] = newSymNode(op) for x in n: patchBody(g, c, x, info, idgen) diff --git a/lib/system.nim b/lib/system.nim index d4835b20b9676..845ab58e66de7 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -365,7 +365,13 @@ proc arrGet[I: Ordinal;T](a: T; i: I): T {. proc arrPut[I: Ordinal;T,S](a: T; i: I; x: S) {.noSideEffect, magic: "ArrPut".} -when defined(nimAllowNonVarDestructor): +when defined(nimAllowNonVarDestructor) and arcLikeMem: + proc `=destroy`*(x: string) {.inline, magic: "Destroy".} = + discard + + proc `=destroy`*[T](x: seq[T]) {.inline, magic: "Destroy".} = + discard + proc `=destroy`*[T](x: ref T) {.inline, magic: "Destroy".} = discard diff --git a/tests/arc/topt_no_cursor.nim b/tests/arc/topt_no_cursor.nim index 39e5c8a9b8875..7cfb0a0d50bd4 100644 --- a/tests/arc/topt_no_cursor.nim +++ b/tests/arc/topt_no_cursor.nim @@ -95,7 +95,7 @@ try: finally: `=destroy`(splitted) finally: - `=destroy_1`(lan_ip) + `=destroy`(lan_ip) -- end of expandArc ------------------------ --expandArc: mergeShadowScope diff --git a/tests/destructor/tv2_cast.nim b/tests/destructor/tv2_cast.nim index 4ff2dc9a07f19..6fcb5994c3a4e 100644 --- a/tests/destructor/tv2_cast.nim +++ b/tests/destructor/tv2_cast.nim @@ -20,8 +20,8 @@ data = :tmpD_2)) :tmpD `=destroy`(:tmpD_2) -`=destroy_1`(:tmpD_1) -`=destroy_1`(data) +`=destroy`(:tmpD_1) +`=destroy`(data) -- end of expandArc ------------------------ --expandArc: main1 @@ -37,8 +37,8 @@ data = :tmpD_1)) :tmpD `=destroy`(:tmpD_1) -`=destroy_1`(data) -`=destroy_1`(s) +`=destroy`(data) +`=destroy`(s) -- end of expandArc ------------------------ --expandArc: main2 @@ -54,7 +54,7 @@ data = :tmpD_1)) :tmpD `=destroy`(:tmpD_1) -`=destroy_1`(data) +`=destroy`(data) `=destroy`(s) -- end of expandArc ------------------------ --expandArc: main3 @@ -73,7 +73,7 @@ data = :tmpD `=destroy`(:tmpD_2) `=destroy`(:tmpD_1) -`=destroy_1`(data) +`=destroy`(data) -- end of expandArc ------------------------ ''' """