Fixed yield in nnkChckRange (#12160)

This commit is contained in:
Yuriy Glukhov 2019-09-10 08:54:06 +03:00 • committed by Andreas Rumpf
commit 60911304b4
2 changed files with 16 additions and 2 deletions

View file

@ -601,7 +601,7 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
result.add(n) result.add(n)
result.add(ctx.newEnvVarAccess(tmp)) result.add(ctx.newEnvVarAccess(tmp))
of nkCallKinds: of nkCallKinds, nkChckRange:
var ns = false var ns = false
for i in 0 ..< n.len: for i in 0 ..< n.len:
n[i] = ctx.lowerStmtListExprs(n[i], ns) n[i] = ctx.lowerStmtListExprs(n[i], ns)
@ -1286,7 +1286,7 @@ proc transformClosureIterator*(g: ModuleGraph; fn: PSym, n: PNode): PNode =
ctx.fn = fn ctx.fn = fn
if getEnvParam(fn).isNil: if getEnvParam(fn).isNil:
# Lambda lifting was not done yet. Use temporary :state sym, which # Lambda lifting was not done yet. Use temporary :state sym, which will
# be handled specially by lambda lifting. Local temp vars (if needed) # be handled specially by lambda lifting. Local temp vars (if needed)
# should folllow the same logic. # should folllow the same logic.
ctx.stateVarSym = newSym(skVar, getIdent(ctx.g.cache, ":state"), fn, fn.info) ctx.stateVarSym = newSym(skVar, getIdent(ctx.g.cache, ":state"), fn, fn.info)

View file

@ -467,5 +467,19 @@ block: #9716
doAssert(b == "hello") doAssert(b == "hello")
test(it, 1, 1, 1) test(it, 1, 1, 1)
block: # nnkChckRange
type Foo = distinct uint64
template yieldDistinct: Foo =
yield 2
Foo(0)
iterator it(): int {.closure.} =
yield 1
var a: int
a = int(yieldDistinct())
yield 3
test(it, 1, 2, 3)
echo "ok" echo "ok"