Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #13739 #13742

Merged
merged 3 commits into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()