mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
Fixed yield in nnkChckRange (#12160)
This commit is contained in:
committed by
Andreas Rumpf
parent
ed1d41c51e
commit
60911304b4
@@ -601,7 +601,7 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode =
|
||||
result.add(n)
|
||||
result.add(ctx.newEnvVarAccess(tmp))
|
||||
|
||||
of nkCallKinds:
|
||||
of nkCallKinds, nkChckRange:
|
||||
var ns = false
|
||||
for i in 0 ..< n.len:
|
||||
n[i] = ctx.lowerStmtListExprs(n[i], ns)
|
||||
@@ -1286,7 +1286,7 @@ proc transformClosureIterator*(g: ModuleGraph; fn: PSym, n: PNode): PNode =
|
||||
ctx.fn = fn
|
||||
|
||||
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)
|
||||
# should folllow the same logic.
|
||||
ctx.stateVarSym = newSym(skVar, getIdent(ctx.g.cache, ":state"), fn, fn.info)
|
||||
|
||||
@@ -467,5 +467,19 @@ block: #9716
|
||||
doAssert(b == "hello")
|
||||
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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user