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
This commit is contained in:
parent
21ecf64d24
commit
f98a3056c6
2 changed files with 63 additions and 15 deletions
35
tests/cnstseq/t2656.nim
Normal file
35
tests/cnstseq/t2656.nim
Normal file
|
|
@ -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 ""
|
||||
Loading…
Add table
Add a link
Reference in a new issue