Skip to content

Commit

Permalink
fixes #13119 (#13128)
Browse files Browse the repository at this point in the history
* fixes #13119
* fixes a regression
  • Loading branch information
Araq authored Jan 14, 2020
1 parent 49d1822 commit d568488
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 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
2 changes: 1 addition & 1 deletion compiler/liftdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
of tyTuple:
fillBodyTup(c, t, body, x, y)
of tyVarargs, tyOpenArray:
if c.kind == attachedDestructor:
if c.kind == attachedDestructor and (tfHasAsgn in t.flags or useNoGc(c, t)):
forallElements(c, t, body, x, y)
else:
discard "cannot copy openArray"
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
4 changes: 2 additions & 2 deletions tests/js/tcopying.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type MyArray = array[1, int]
proc changeArray(a: var MyArray) =
a = [123]

var a : MyArray
var a: MyArray
changeArray(a)
echo a[0]

Expand All @@ -34,7 +34,7 @@ block:
ary2: array[3, int]

let ary1 = [1, 2, 3]
var obj = TestObj(ary2:ary1)
var obj = TestObj(ary2: ary1)

obj.ary2[1] = 9

Expand Down

0 comments on commit d568488

Please sign in to comment.