]> granicus.if.org Git - vim/commitdiff
patch 8.2.2878: Vim9: for loop list unpack only allows for one "_" v8.2.2878
authorBram Moolenaar <Bram@vim.org>
Sat, 22 May 2021 19:40:39 +0000 (21:40 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 May 2021 19:40:39 +0000 (21:40 +0200)
Problem:    Vim9: for loop list unpack only allows for one "_".
Solution:   Drop the value when the variable is "_". (closes #8232)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 0e77b58b638f09fc7411fc2b9c5ce8a3f5b8b4b8..7114ae41e1bf3ffc656b197381704a3a90bb0f59 100644 (file)
@@ -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)
 
index 82ecd0a9347603b686bd181dd93b42867a40113f..0223ae2a4d26ca8abc7c3d2196f438b6924842ab 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2878,
 /**/
     2877,
 /**/
index 5e912dd8816c8c81f54f26613285fdcd18294c03..cb91c3ccb9e07c33aa90f073f22b01e19f8c303b 100644 (file)
@@ -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)