Merge pull request #7971 from yglukhov/yield-in-dotexpr
Fixed yield in nkDotExpr. Fixes #7969.
This commit is contained in:
commit
42329e0a70
2 changed files with 39 additions and 2 deletions
|
|
@ -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[0] = newSymNode(ctx.g.getSysSym(n[0].info, "true"))
|
||||||
n[1] = newBody
|
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:
|
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)
|
||||||
|
|
@ -843,8 +856,8 @@ proc transformClosureIteratorBody(ctx: var Ctx, n: PNode, gotoOut: PNode): PNode
|
||||||
result[0] = ctx.transformClosureIteratorBody(result[0], gotoOut)
|
result[0] = ctx.transformClosureIteratorBody(result[0], gotoOut)
|
||||||
|
|
||||||
of nkElifBranch, nkElifExpr, nkOfBranch:
|
of nkElifBranch, nkElifExpr, nkOfBranch:
|
||||||
result[1] = addGotoOut(result[1], gotoOut)
|
result[^1] = addGotoOut(result[^1], gotoOut)
|
||||||
result[1] = ctx.transformClosureIteratorBody(result[1], gotoOut)
|
result[^1] = ctx.transformClosureIteratorBody(result[^1], gotoOut)
|
||||||
|
|
||||||
of nkIfStmt, nkCaseStmt:
|
of nkIfStmt, nkCaseStmt:
|
||||||
for i in 0 ..< n.len:
|
for i in 0 ..< n.len:
|
||||||
|
|
|
||||||
|
|
@ -368,5 +368,29 @@ block: # Short cirquits
|
||||||
|
|
||||||
test(it, 1, 0, 0)
|
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"
|
echo "ok"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue