Skip to content

Commit b777da9

Browse files
committed
patch 8.2.2878: Vim9: for loop list unpack only allows for one "_"
Problem: Vim9: for loop list unpack only allows for one "_". Solution: Drop the value when the variable is "_". (closes #8232)
1 parent 1e61566 commit b777da9

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,12 @@ def Test_for_loop_unpack()
25002500
endfor
25012501
assert_equal(['global', 'buf', 'win', 'tab', '1', '2', '3', '4'], slist)
25022502
unlet! g:globalvar b:bufvar w:winvar t:tabvar
2503+
2504+
var res = []
2505+
for [_, n, _] in [[1, 2, 3], [4, 5, 6]]
2506+
res->add(n)
2507+
endfor
2508+
assert_equal([2, 5], res)
25032509
END
25042510
CheckDefAndScriptSuccess(lines)
25052511

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2878,
753755
/**/
754756
2877,
755757
/**/

src/vim9compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7776,6 +7776,12 @@ compile_for(char_u *arg_start, cctx_T *cctx)
77767776
0, 0, type, name) == FAIL)
77777777
goto failed;
77787778
}
7779+
else if (varlen == 1 && *arg == '_')
7780+
{
7781+
// Assigning to "_": drop the value.
7782+
if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL)
7783+
goto failed;
7784+
}
77797785
else
77807786
{
77817787
if (lookup_local(arg, varlen, NULL, cctx) == OK)

0 commit comments

Comments
 (0)