Skip to content

Commit a870623

Browse files
authored
fixes #13622 (#13679)
1 parent 3f1a85b commit a870623

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

compiler/injectdestructors.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type
3131
emptyNode: PNode
3232
otherRead: PNode
3333
inLoop: int
34+
declaredVars: IntSet # variables we already moved to the top level
3435
uninit: IntSet # set of uninit'ed vars
3536
uninitComputed: bool
3637

@@ -345,7 +346,7 @@ proc passCopyToSink(n: PNode; c: var Con): PNode =
345346
var m = genCopy(c, tmp, n)
346347
m.add p(n, c, normal)
347348
result.add m
348-
if isLValue(n) and not isClosureEnv(n):
349+
if isLValue(n) and not isClosureEnv(n) and n.typ.skipTypes(abstractInst).kind != tyRef:
349350
message(c.graph.config, n.info, hintPerformance,
350351
("passing '$1' to a sink parameter introduces an implicit copy; " &
351352
"use 'move($1)' to prevent it") % $n)
@@ -589,7 +590,8 @@ proc p(n: PNode; c: var Con; mode: ProcessMode): PNode =
589590
if v.kind == nkSym:
590591
if sfCompileTime in v.sym.flags: continue
591592
# move the variable declaration to the top of the frame:
592-
c.addTopVar v
593+
if not containsOrIncl(c.declaredVars, v.sym.id):
594+
c.addTopVar v
593595
# make sure it's destroyed at the end of the proc:
594596
if not isUnpackedTuple(v) and sfThread notin v.sym.flags:
595597
# do not destroy thread vars for now at all for consistency.

tests/arc/tstrformat.nim

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
discard """
2+
output: '''verstuff'''
3+
cmd: "nim c --gc:arc $file"
4+
"""
5+
6+
# bug #13622
7+
8+
import strformat
9+
10+
template necho*(args: string) {.dirty.} =
11+
if getCurrentException() != nil:
12+
echo args
13+
else:
14+
stdout.writeLine(args)
15+
16+
proc main(cond: bool; arg: string) =
17+
if cond:
18+
necho &"ver{arg}\n"
19+
20+
main(true, "stuff")

0 commit comments

Comments
 (0)