Fixed yield in dotExpr and nkOfBranch lowering. Closes #7969.

This commit is contained in:
Yuriy Glukhov
2018-06-06 16:17:24 +03:00
parent e957d369b1
commit 0ec2b33c50
2 changed files with 39 additions and 2 deletions

View File

@@ -735,6 +735,19 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
n[0] = newSymNode(ctx.g.getSysSym(n[0].info, "true"))
n[1] = newBody
of nkDotExpr:
var ns = false
n[0] = ctx.lowerStmtListExprs(n[0], ns)
if ns:
needsSplit = true
result = newNodeI(nkStmtListExpr, n.info)
result.typ = n.typ
let (st, ex) = exprToStmtList(n[0])
result.add(st)
n[0] = ex
result.add(n)
else:
for i in 0 ..< n.len:
n[i] = ctx.lowerStmtListExprs(n[i], needsSplit)
@@ -843,8 +856,8 @@ proc transformClosureIteratorBody(ctx: var Ctx, n: PNode, gotoOut: PNode): PNode
result[0] = ctx.transformClosureIteratorBody(result[0], gotoOut)
of nkElifBranch, nkElifExpr, nkOfBranch:
result[1] = addGotoOut(result[1], gotoOut)
result[1] = ctx.transformClosureIteratorBody(result[1], gotoOut)
result[^1] = addGotoOut(result[^1], gotoOut)
result[^1] = ctx.transformClosureIteratorBody(result[^1], gotoOut)
of nkIfStmt, nkCaseStmt:
for i in 0 ..< n.len:

View File

@@ -368,5 +368,29 @@ block: # Short cirquits
test(it, 1, 0, 0)
block: #7969
type
SomeObj = object
id: int
iterator it(): int {.closure.} =
template yieldAndSomeObj: SomeObj =
var s: SomeObj
s.id = 2
yield 1
s
checkpoint(yieldAndSomeObj().id)
var i = 5
case i
of 0:
checkpoint(123)
of 1, 2, 5:
checkpoint(3)
else:
checkpoint(123)
test(it, 1, 2, 3)
echo "ok"