Fixed yield in nkBlockExpr

This commit is contained in:
Yuriy Glukhov 2018-06-07 00:14:56 +03:00
commit fef60716bf
2 changed files with 29 additions and 2 deletions

View file

@ -442,7 +442,6 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
n[i] = ctx.lowerStmtListExprs(n[i], ns) n[i] = ctx.lowerStmtListExprs(n[i], ns)
if ns: if ns:
assert(n[0].kind == nkStmtListExpr)
result = newNodeI(nkStmtList, n.info) result = newNodeI(nkStmtList, n.info)
let (st, ex) = exprToStmtList(n[0]) let (st, ex) = exprToStmtList(n[0])
result.add(st) 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) c[^1] = ctx.lowerStmtListExprs(c[^1], ns)
if ns: if ns:
needsSplit = true needsSplit = true
assert(c[^1].kind == nkStmtListExpr)
let (st, ex) = exprToStmtList(c[^1]) let (st, ex) = exprToStmtList(c[^1])
result.add(st) result.add(st)
c[^1] = ex c[^1] = ex
@ -748,6 +746,20 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
n[0] = ex n[0] = ex
result.add(n) 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: else:
for i in 0 ..< n.len: for i in 0 ..< n.len:
n[i] = ctx.lowerStmtListExprs(n[i], needsSplit) n[i] = ctx.lowerStmtListExprs(n[i], needsSplit)

View file

@ -393,4 +393,19 @@ block: #7969
test(it, 1, 2, 3) 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" echo "ok"