This commit is contained in:
Araq
2019-07-03 12:53:56 +02:00
parent 476b4ff372
commit c0db1705dc
2 changed files with 25 additions and 3 deletions

View File

@@ -150,6 +150,7 @@ type
graph: ModuleGraph
emptyNode: PNode
otherRead: PNode
inLoop: int
uninit: IntSet # set of uninit'ed vars
uninitComputed: bool
@@ -750,7 +751,7 @@ proc p(n: PNode; c: var Con): PNode =
for i in 0..<n.len:
let it = n[i]
let L = it.len
let ri = it[L-1]
var ri = it[L-1]
if it.kind == nkVarTuple and hasDestructor(ri.typ):
let x = lowerTupleUnpacking(c.graph, it, c.owner)
result.add p(x, c)
@@ -764,6 +765,8 @@ proc p(n: PNode; c: var Con): PNode =
# make sure it's destroyed at the end of the proc:
if not isUnpackedTuple(it[0].sym):
c.destroys.add genDestroy(c, v.typ, v)
if ri.kind == nkEmpty and c.inLoop > 0:
ri = genDefaultCall(v.typ, c, v.info)
if ri.kind != nkEmpty:
let r = moveOrCopy(v, ri, c)
result.add r
@@ -826,6 +829,11 @@ proc p(n: PNode; c: var Con): PNode =
else:
result = copyNode(n)
recurse(n, result)
of nkForStmt, nkParForStmt, nkWhileStmt:
inc c.inLoop
result = copyNode(n)
recurse(n, result)
dec c.inLoop
else:
result = copyNode(n)
recurse(n, result)

View File

@@ -1,9 +1,13 @@
discard """
exitcode: 0
output: ""
output: '''@[0]
@[1]
@[2]
@[3]'''
joinable: false
"""
# bug #6434
type
Foo* = object
boo: int
@@ -25,3 +29,13 @@ var (a, b, _) = test()
doAssert assign_counter == 0
doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation
# bug #11510
proc main =
for i in 0 ..< 4:
var buffer: seq[int] # = @[] # uncomment to make it work
# var buffer: string # also this is broken
buffer.add i
echo buffer
main()