fixes #11510
This commit is contained in:
parent
476b4ff372
commit
c0db1705dc
2 changed files with 25 additions and 3 deletions
|
|
@ -150,6 +150,7 @@ type
|
||||||
graph: ModuleGraph
|
graph: ModuleGraph
|
||||||
emptyNode: PNode
|
emptyNode: PNode
|
||||||
otherRead: PNode
|
otherRead: PNode
|
||||||
|
inLoop: int
|
||||||
uninit: IntSet # set of uninit'ed vars
|
uninit: IntSet # set of uninit'ed vars
|
||||||
uninitComputed: bool
|
uninitComputed: bool
|
||||||
|
|
||||||
|
|
@ -750,7 +751,7 @@ proc p(n: PNode; c: var Con): PNode =
|
||||||
for i in 0..<n.len:
|
for i in 0..<n.len:
|
||||||
let it = n[i]
|
let it = n[i]
|
||||||
let L = it.len
|
let L = it.len
|
||||||
let ri = it[L-1]
|
var ri = it[L-1]
|
||||||
if it.kind == nkVarTuple and hasDestructor(ri.typ):
|
if it.kind == nkVarTuple and hasDestructor(ri.typ):
|
||||||
let x = lowerTupleUnpacking(c.graph, it, c.owner)
|
let x = lowerTupleUnpacking(c.graph, it, c.owner)
|
||||||
result.add p(x, c)
|
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:
|
# make sure it's destroyed at the end of the proc:
|
||||||
if not isUnpackedTuple(it[0].sym):
|
if not isUnpackedTuple(it[0].sym):
|
||||||
c.destroys.add genDestroy(c, v.typ, v)
|
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:
|
if ri.kind != nkEmpty:
|
||||||
let r = moveOrCopy(v, ri, c)
|
let r = moveOrCopy(v, ri, c)
|
||||||
result.add r
|
result.add r
|
||||||
|
|
@ -826,6 +829,11 @@ proc p(n: PNode; c: var Con): PNode =
|
||||||
else:
|
else:
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
recurse(n, result)
|
recurse(n, result)
|
||||||
|
of nkForStmt, nkParForStmt, nkWhileStmt:
|
||||||
|
inc c.inLoop
|
||||||
|
result = copyNode(n)
|
||||||
|
recurse(n, result)
|
||||||
|
dec c.inLoop
|
||||||
else:
|
else:
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
recurse(n, result)
|
recurse(n, result)
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
discard """
|
discard """
|
||||||
exitcode: 0
|
output: '''@[0]
|
||||||
output: ""
|
@[1]
|
||||||
|
@[2]
|
||||||
|
@[3]'''
|
||||||
joinable: false
|
joinable: false
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# bug #6434
|
||||||
|
|
||||||
type
|
type
|
||||||
Foo* = object
|
Foo* = object
|
||||||
boo: int
|
boo: int
|
||||||
|
|
@ -25,3 +29,13 @@ var (a, b, _) = test()
|
||||||
|
|
||||||
doAssert assign_counter == 0
|
doAssert assign_counter == 0
|
||||||
doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation
|
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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue