1
0
forked from aniani/vim

patch 9.0.0460: loop variable can't be found

Problem:    Loop variable can't be found.
Solution:   Adjust block_id of the loop variable each round.
This commit is contained in:
Bram Moolenaar
2022-09-14 00:30:51 +01:00
parent 353b68a991
commit 766ae5b252
11 changed files with 86 additions and 25 deletions

View File

@@ -2259,7 +2259,21 @@ def Test_for_loop()
enddef
def Test_for_loop_with_closure()
# using the loop variable in a closure results in the last used value
var lines =<< trim END
var flist: list<func>
for i in range(5)
flist[i] = () => i
endfor
for i in range(5)
assert_equal(4, flist[i]())
endfor
END
v9.CheckDefAndScriptSuccess(lines)
# using a local variable set to the loop variable in a closure results in the
# value at that moment
lines =<< trim END
var flist: list<func>
for i in range(5)
var inloop = i