diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-10-09 19:43:31 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-10-09 19:43:31 +0200 |
commit | f98a3056c6c98ba546a302040679fb6226f555f6 (patch) | |
tree | 29b0f68865a71045f7a8dba29b1f6be45748f967 /tests | |
parent | 21ecf64d243a93fab29aed6d3e439918d72c6e16 (diff) | |
download | Nim-f98a3056c6c98ba546a302040679fb6226f555f6.tar.gz |
Fix transformation of yield in inline context (#9135)
When the loop variables are part of the envP block it is not safe to use a nkFastAsgn. Fixes #2656
Diffstat (limited to 'tests')
-rw-r--r-- | tests/cnstseq/t2656.nim | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/cnstseq/t2656.nim b/tests/cnstseq/t2656.nim new file mode 100644 index 000000000..c6ff182f3 --- /dev/null +++ b/tests/cnstseq/t2656.nim @@ -0,0 +1,35 @@ +discard """ + output: ''' +onetwothree +onetwothree +onetwothree +one1two2three3 +''' +""" + +iterator it1(args: seq[string]): string = + for s in args: yield s +iterator it2(args: seq[string]): string {.closure.} = + for s in args: yield s +iterator it3(args: openArray[string]): string {.closure.} = + for s in args: yield s +iterator it4(args: openArray[(string, string)]): string {.closure.} = + for s1, s2 in items(args): yield s1 & s2 + +block: + const myConstSeq = @["one", "two", "three"] + for s in it1(myConstSeq): + stdout.write s + echo "" + for s in it2(myConstSeq): + stdout.write s + echo "" + for s in it3(myConstSeq): + stdout.write s + echo "" + +block: + const myConstSeq = @[("one", "1"), ("two", "2"), ("three", "3")] + for s in it4(myConstSeq): + stdout.write s + echo "" |