Skip to content

Commit

Permalink
fix #13739 (#13742)
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 authored Apr 7, 2020
1 parent 92c4aad commit 37692ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
9 changes: 4 additions & 5 deletions compiler/transf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
of nkBracket:
return paFastAsgnTakeTypeFromArg
else:
return paDirectMapping # XXX really correct?
# what if ``arg`` has side-effects?
# XXX incorrect, causes #13417 when `arg` has side effects.
return paDirectMapping
case arg.kind
of nkEmpty..nkNilLit:
result = paDirectMapping
Expand Down Expand Up @@ -671,9 +671,8 @@ proc transformFor(c: PTransf, n: PNode): PNode =
idNodeTablePut(newC.mapping, formal, arg)
# XXX BUG still not correct if the arg has a side effect!
of paComplexOpenarray:
let typ = newType(tySequence, formal.owner)
addSonSkipIntLit(typ, formal.typ[0])
var temp = newTemp(c, typ, formal.info)
# arrays will deep copy here (pretty bad).
var temp = newTemp(c, arg.typ, formal.info)
addVar(v, temp)
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg))
idNodeTablePut(newC.mapping, formal, temp)
Expand Down
27 changes: 27 additions & 0 deletions tests/iter/titer_issues.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ end
1
2
7
9002
9004
9006
9008
9010
9012
9014
9016
9018
'''
"""

Expand Down Expand Up @@ -213,3 +222,21 @@ block t2023_objiter:

var o = init()
echo(o.iter())


block:
# issue #13739
iterator myIter(arg: openarray[int]): int =
var tmp = 0
let len = arg.len
while tmp < len:
yield arg[tmp] * 2
inc tmp

proc someProc() =
var data = [4501,4502,4503,4504,4505,4506,4507,4508,4509]
# StmtListExpr should not get special treatment.
for x in myIter((discard;data)):
echo x

someProc()

0 comments on commit 37692ba

Please sign in to comment.