1
0
forked from aniani/vim

patch 8.2.2763: Vim9: cannot use type in for loop unpack at script level

Problem:    Vim9: cannot use type in for loop unpack at script level.
Solution:   Advance over the type name.
This commit is contained in:
Bram Moolenaar
2021-04-14 13:30:46 +02:00
parent f62d73933a
commit a3589a0d6c
3 changed files with 18 additions and 9 deletions

View File

@@ -1523,7 +1523,7 @@ ex_let_one(
else else
{ {
set_var_lval(&lv, p, tv, copy, flags, op, var_idx); set_var_lval(&lv, p, tv, copy, flags, op, var_idx);
arg_end = p; arg_end = lv.ll_name_end;
} }
} }
clear_lval(&lv); clear_lval(&lv);

View File

@@ -2336,8 +2336,22 @@ def Test_for_loop()
endfor endfor
assert_equal(6, total) assert_equal(6, total)
# loop over string # with type
total = 0
for n: number in [1, 2, 3]
total += n
endfor
assert_equal(6, total)
# unpack with type
var res = '' var res = ''
for [n: number, s: string] in [[1, 'a'], [2, 'b']]
res ..= n .. s
endfor
assert_equal('1a2b', res)
# loop over string
res = ''
for c in 'aéc̀d' for c in 'aéc̀d'
res ..= c .. '-' res ..= c .. '-'
endfor endfor
@@ -2364,13 +2378,6 @@ def Test_for_loop()
assert_equal([{a: 'Cat', counter: 12}], foo) assert_equal([{a: 'Cat', counter: 12}], foo)
END END
CheckDefAndScriptSuccess(lines) CheckDefAndScriptSuccess(lines)
# TODO: should also work at script level
var res = ""
for [n: number, s: string] in [[1, 'a'], [2, 'b']]
res ..= n .. s
endfor
assert_equal('1a2b', res)
enddef enddef
def Test_for_loop_fails() def Test_for_loop_fails()

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2763,
/**/ /**/
2762, 2762,
/**/ /**/