mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-25 16:53:59 +00:00
Fixes 9716 [backport] (#9790)
* reuse temporary variable * fixes #9716 [backport] * Declare local vars in safer place
This commit is contained in:
committed by
Andreas Rumpf
parent
47d0582ebf
commit
410fd1deae
@@ -403,7 +403,7 @@ block: # yield in blockexpr
|
||||
|
||||
test(it, 1, 2, 3)
|
||||
|
||||
block: #8851
|
||||
block: #8851
|
||||
type
|
||||
Foo = ref object of RootObj
|
||||
template someFoo(): Foo =
|
||||
@@ -454,5 +454,18 @@ block: #9694 - yield in ObjConstr
|
||||
|
||||
test(it, 1, 2)
|
||||
|
||||
block: #9716
|
||||
iterator it(): int {.closure.} =
|
||||
var a = 0
|
||||
for i in 1 .. 3:
|
||||
var a: int # Make sure the "local" var is reset
|
||||
var b: string # ditto
|
||||
yield 1
|
||||
a += 5
|
||||
b &= "hello"
|
||||
doAssert(a == 5)
|
||||
doAssert(b == "hello")
|
||||
test(it, 1, 1, 1)
|
||||
|
||||
echo "ok"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user