1
0
forked from aniani/vim

patch 9.0.0724: closure in compiled function gets same variable in block

Problem:    Closure in compiled function gets same variable in block.
Solution:   At the end of a block to not always reset the variable count.
            (issue #11094)
This commit is contained in:
Bram Moolenaar
2022-10-11 20:04:09 +01:00
parent a9a364872e
commit a275f2cdcc
4 changed files with 49 additions and 18 deletions

View File

@@ -2314,6 +2314,36 @@ def Test_for_loop_with_closure()
END
v9.CheckDefAndScriptSuccess(lines)
# also with an extra block level
lines =<< trim END
var flist: list<func>
for i in range(5)
{
var inloop = i
flist[i] = () => inloop
}
endfor
for i in range(5)
assert_equal(i, flist[i]())
endfor
END
v9.CheckDefAndScriptSuccess(lines)
# and declaration in higher block
lines =<< trim END
var flist: list<func>
for i in range(5)
var inloop = i
{
flist[i] = () => inloop
}
endfor
for i in range(5)
assert_equal(i, flist[i]())
endfor
END
v9.CheckDefAndScriptSuccess(lines)
lines =<< trim END
var flist: list<func>
for i in range(5)