Skip to content

Commit

Permalink
fixes #13119
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Jan 13, 2020
1 parent bf2e052 commit dab0ed1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions compiler/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ proc passCopyToSink(n: PNode; c: var Con): PNode =
("passing '$1' to a sink parameter introduces an implicit copy; " &
"use 'move($1)' to prevent it") % $n)
else:
if c.graph.config.selectedGC in {gcArc, gcOrc}:
assert(not containsGarbageCollectedRef(n.typ))
result.add newTree(nkAsgn, tmp, p(n, c, normal))
result.add tmp

Expand Down
10 changes: 8 additions & 2 deletions compiler/sempass2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -907,9 +907,15 @@ proc track(tracked: PEffects, n: PNode) =
nkMacroDef, nkTemplateDef, nkLambda, nkDo, nkFuncDef:
discard
of nkCast, nkHiddenStdConv, nkHiddenSubConv, nkConv:
if n.len == 2: track(tracked, n[1])
if n.len == 2:
track(tracked, n[1])
if tracked.owner.kind != skMacro:
createTypeBoundOps(tracked, n.typ, n.info)
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
if n.len == 1: track(tracked, n[0])
if n.len == 1:
track(tracked, n[0])
if tracked.owner.kind != skMacro:
createTypeBoundOps(tracked, n.typ, n.info)
of nkBracket:
for i in 0..<n.safeLen: track(tracked, n[i])
if tracked.owner.kind != skMacro:
Expand Down
12 changes: 12 additions & 0 deletions tests/destructor/tarc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ discard """
@[1, 2, 3]
Success
@["a", "b", "c"]
Hello
0'''
cmd: '''nim c --gc:arc $file'''
"""
Expand Down Expand Up @@ -114,4 +115,15 @@ proc bug12964*() =

bug12964()

# bug #13119
import streams

proc bug13119 =
var m = newStringStream("Hello world")
let buffer = m.readStr(5)
echo buffer
m.close

bug13119()

echo getOccupiedMem() - startMem

0 comments on commit dab0ed1

Please sign in to comment.