From 413dff03a085b61d5247d3a200c878d6ee2dc522 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 1 Jul 2019 12:28:52 +0200 Subject: fixes #11614 --- compiler/injectdestructors.nim | 2 +- tests/destructor/tgcdestructors.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 61f47cdfe..ef65e788f 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -498,7 +498,7 @@ proc pArg(arg: PNode; c: var Con; isSink: bool): PNode = # to disable the destructor which we have not elided sinkParamIsLastReadCheck(c, arg) result = destructiveMoveVar(arg, c) - elif arg.kind == nkSym and arg.sym.kind in InterestingSyms and isLastRead(arg, c): + elif isAnalysableFieldAccess(arg, c.owner) and isLastRead(arg, c): # it is the last read, can be sinked. We need to reset the memory # to disable the destructor which we have not elided result = destructiveMoveVar(arg, c) diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim index 36dec9326..7eb865915 100644 --- a/tests/destructor/tgcdestructors.nim +++ b/tests/destructor/tgcdestructors.nim @@ -9,6 +9,7 @@ ha a: @[4, 2, 3] 0 30 +true 41 41''' """ @@ -190,6 +191,17 @@ proc mainSeqOfCap = mainSeqOfCap() +# bug #11614 + +let ga = "foo" + +proc takeAinArray = + let b = [ga] + +takeAinArray() +echo ga == "foo" + + #echo s let (a, d) = allocCounters() discard cprintf("%ld %ld\n", a, d) -- cgit 1.4.1-2-gfad0