0
0
mirror of https://github.com/vim/vim.git synced 2025-10-01 04:54:07 -04:00

patch 8.2.2770: Vim9: type of loop variable is not used

Problem:    Vim9: type of loop variable is not used.
Solution:   Parse and check the variable type. (closes #8107)
This commit is contained in:
Bram Moolenaar
2021-04-15 21:48:32 +02:00
parent 6bc00699c5
commit fe090eb58f
3 changed files with 35 additions and 5 deletions

View File

@@ -2343,6 +2343,12 @@ def Test_for_loop()
endfor
assert_equal(6, total)
var chars = ''
for s: string in 'foobar'
chars ..= s
endfor
assert_equal('foobar', chars)
# unpack with type
var res = ''
for [n: number, s: string] in [[1, 'a'], [2, 'b']]
@@ -2408,6 +2414,12 @@ def Test_for_loop_fails()
endfor
END
CheckDefAndScriptFailure2(lines, 'E1018:', 'E46:', 3)
lines =<< trim END
for nr: number in ['foo']
endfor
END
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
enddef
def Test_for_loop_script_var()