summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-05-22 21:40:39 +0200
committerBram Moolenaar <Bram@vim.org>2021-05-22 21:40:39 +0200
commitb777da9be8eb421982e567702db3195475383dec (patch)
tree5e5bf5707e42d8a208bf9cc054047b718fcc38cf
parent1e615669c0f1f4125001b2c01c30b00d8c68035e (diff)
downloadvim-git-b777da9be8eb421982e567702db3195475383dec.tar.gz
patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"v8.2.2878
Problem: Vim9: for loop list unpack only allows for one "_". Solution: Drop the value when the variable is "_". (closes #8232)
-rw-r--r--src/testdir/test_vim9_script.vim6
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c6
3 files changed, 14 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 0e77b58b6..7114ae41e 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -2500,6 +2500,12 @@ def Test_for_loop_unpack()
endfor
assert_equal(['global', 'buf', 'win', 'tab', '1', '2', '3', '4'], slist)
unlet! g:globalvar b:bufvar w:winvar t:tabvar
+
+ var res = []
+ for [_, n, _] in [[1, 2, 3], [4, 5, 6]]
+ res->add(n)
+ endfor
+ assert_equal([2, 5], res)
END
CheckDefAndScriptSuccess(lines)
diff --git a/src/version.c b/src/version.c
index 82ecd0a93..0223ae2a4 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 */
/**/
+ 2878,
+/**/
2877,
/**/
2876,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 5e912dd88..cb91c3ccb 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -7776,6 +7776,12 @@ compile_for(char_u *arg_start, cctx_T *cctx)
0, 0, type, name) == FAIL)
goto failed;
}
+ else if (varlen == 1 && *arg == '_')
+ {
+ // Assigning to "_": drop the value.
+ if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
+ goto failed;
+ }
else
{
if (lookup_local(arg, varlen, NULL, cctx) == OK)