mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 01:14:41 +00:00
fixes #11510
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user