* fixes #13119
* fixes a regression
This commit is contained in:
Andreas Rumpf
2020-01-14 09:56:08 +01:00
committed by GitHub
parent 49d1822c8f
commit d56848878c
5 changed files with 25 additions and 5 deletions

View File

@@ -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

View File

@@ -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"

View File

@@ -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:

View File

@@ -3,6 +3,7 @@ discard """
@[1, 2, 3]
Success
@["a", "b", "c"]
Hello
0'''
cmd: '''nim c --gc:arc $file'''
"""
@@ -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

View File

@@ -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]
@@ -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