Fixes 9716 [backport] (#9790)

* reuse temporary variable
* fixes #9716 [backport]
* Declare local vars in safer place
This commit is contained in:
Yuriy Glukhov
2018-11-24 11:50:48 +02:00
committed by Andreas Rumpf
parent 47d0582ebf
commit 410fd1deae
4 changed files with 30 additions and 14 deletions

View File

@@ -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"