Skip to content

Commit

Permalink
patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Browse files Browse the repository at this point in the history
Problem:    Vim9: for loop list unpack only allows for one "_".
Solution:   Drop the value when the variable is "_". (closes #8232)
  • Loading branch information
brammool committed May 22, 2021
1 parent 1e61566 commit b777da9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/testdir/test_vim9_script.vim
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2878,
/**/
2877,
/**/
Expand Down
6 changes: 6 additions & 0 deletions src/vim9compile.c
Expand Up @@ -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)
Expand Down

0 comments on commit b777da9

Please sign in to comment.