summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-14 13:30:46 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-14 13:30:46 +0200
commita3589a0d6cdb314e70421c0f2e5a2d1abf68e597 (patch)
treea3cfd5f8e0f4039679ff7fbf8a0de1db8f9fed62
parentf62d73933af7830301989eb8162ce94a80e61fbf (diff)
downloadvim-git-a3589a0d6cdb314e70421c0f2e5a2d1abf68e597.tar.gz
patch 8.2.2763: Vim9: cannot use type in for loop unpack at script levelv8.2.2763
Problem: Vim9: cannot use type in for loop unpack at script level. Solution: Advance over the type name.
-rw-r--r--src/evalvars.c2
-rw-r--r--src/testdir/test_vim9_script.vim23
-rw-r--r--src/version.c2
3 files changed, 18 insertions, 9 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index eb9ad6da1..ebfc42b18 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -1523,7 +1523,7 @@ ex_let_one(
else
{
set_var_lval(&lv, p, tv, copy, flags, op, var_idx);
- arg_end = p;
+ arg_end = lv.ll_name_end;
}
}
clear_lval(&lv);
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index af7e5fdbb..03da2fd86 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2336,8 +2336,22 @@ def Test_for_loop()
endfor
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 = ''
+ 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'
res ..= c .. '-'
endfor
@@ -2364,13 +2378,6 @@ def Test_for_loop()
assert_equal([{a: 'Cat', counter: 12}], foo)
END
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
def Test_for_loop_fails()
diff --git a/src/version.c b/src/version.c
index 72da5f91b..3dee026c1 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2763,
+/**/
2762,
/**/
2761,