0
0
mirror of https://github.com/vim/vim.git synced 2025-11-09 10:37:17 -05:00

patch 9.0.0535: closure gets wrong value in for loop with two loop variables

Problem:    Closure gets wrong value in for loop with two loop variables.
Solution:   Correctly compute the number of loop variables to clear.
This commit is contained in:
Bram Moolenaar
2022-09-21 18:59:14 +01:00
parent ec5e1483eb
commit e8e369a796
5 changed files with 34 additions and 5 deletions

View File

@@ -2323,6 +2323,27 @@ def Test_for_loop_with_closure()
endfor
END
v9.CheckDefAndScriptSuccess(lines)
# using two loop variables
lines =<< trim END
var lv_list: list<func>
var copy_list: list<func>
for [idx, c] in items('word')
var lidx = idx
var lc = c
lv_list[idx] = () => {
return idx .. c
}
copy_list[idx] = () => {
return lidx .. lc
}
endfor
for [i, c] in items('word')
assert_equal(3 .. 'd', lv_list[i]())
assert_equal(i .. c, copy_list[i]())
endfor
END
v9.CheckDefAndScriptSuccess(lines)
enddef
def Test_define_global_closure_in_loops()