mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 19:22:40 +00:00
Fixed yield in nkBlockExpr
This commit is contained in:
@@ -442,7 +442,6 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
|
||||
n[i] = ctx.lowerStmtListExprs(n[i], ns)
|
||||
|
||||
if ns:
|
||||
assert(n[0].kind == nkStmtListExpr)
|
||||
result = newNodeI(nkStmtList, n.info)
|
||||
let (st, ex) = exprToStmtList(n[0])
|
||||
result.add(st)
|
||||
@@ -662,7 +661,6 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
|
||||
c[^1] = ctx.lowerStmtListExprs(c[^1], ns)
|
||||
if ns:
|
||||
needsSplit = true
|
||||
assert(c[^1].kind == nkStmtListExpr)
|
||||
let (st, ex) = exprToStmtList(c[^1])
|
||||
result.add(st)
|
||||
c[^1] = ex
|
||||
@@ -748,6 +746,20 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
|
||||
n[0] = ex
|
||||
result.add(n)
|
||||
|
||||
of nkBlockExpr:
|
||||
var ns = false
|
||||
n[1] = ctx.lowerStmtListExprs(n[1], ns)
|
||||
if ns:
|
||||
needsSplit = true
|
||||
result = newNodeI(nkStmtListExpr, n.info)
|
||||
result.typ = n.typ
|
||||
let (st, ex) = exprToStmtList(n[1])
|
||||
n.kind = nkBlockStmt
|
||||
n.typ = nil
|
||||
n[1] = st
|
||||
result.add(n)
|
||||
result.add(ex)
|
||||
|
||||
else:
|
||||
for i in 0 ..< n.len:
|
||||
n[i] = ctx.lowerStmtListExprs(n[i], needsSplit)
|
||||
|
||||
@@ -393,4 +393,19 @@ block: #7969
|
||||
|
||||
test(it, 1, 2, 3)
|
||||
|
||||
block: # yield in blockexpr
|
||||
type
|
||||
SomeObj = object
|
||||
id: int
|
||||
|
||||
iterator it(): int {.closure.} =
|
||||
yield(block:
|
||||
checkpoint(1)
|
||||
yield 2
|
||||
3
|
||||
)
|
||||
|
||||
test(it, 1, 2, 3)
|
||||
|
||||
|
||||
echo "ok"
|
||||
|
||||
Reference in New Issue
Block a user