0
0
mirror of https://github.com/vim/vim.git synced 2025-10-04 05:25:06 -04:00

patch 8.2.2080: Vim9: no proper error message for using s:var in for loop

Problem:    Vim9: no proper error message for using s:var in for loop.
Solution:   Give a specific error.
This commit is contained in:
Bram Moolenaar
2020-12-02 14:24:30 +01:00
parent 38bd8de551
commit ea87069d78
3 changed files with 29 additions and 0 deletions

View File

@@ -1884,6 +1884,27 @@ def Test_for_loop_fails()
CheckDefFailure(['for i in range(3)', 'echo 3'], 'E170:')
enddef
def Test_for_loop_script_var()
# cannot use s:var in a :def function
CheckDefFailure(['for s:var in range(3)', 'echo 3'], 'E1101:')
# can use s:var in Vim9 script, with or without s:
var lines =<< trim END
vim9script
var total = 0
for s:var in [1, 2, 3]
total += s:var
endfor
assert_equal(6, total)
total = 0
for var in [1, 2, 3]
total += var
endfor
assert_equal(6, total)
END
enddef
def Test_for_loop_unpack()
var lines =<< trim END
var result = []