]> granicus.if.org Git - vim/commitdiff
patch 8.2.2072: Vim9: list assign not well tested v8.2.2072
authorBram Moolenaar <Bram@vim.org>
Mon, 30 Nov 2020 20:40:03 +0000 (21:40 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 30 Nov 2020 20:40:03 +0000 (21:40 +0100)
Problem:    Vim9: list assign not well tested.
Solution:   Test with different destinations.  Fix white space error.

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

index 421229fd01013cbbdbc384a0c87c87b159a83d21..7658d8303ae4b8018a159f99136a89be7f0c334e 100644 (file)
@@ -657,6 +657,24 @@ def Test_assignment_var_list()
       assert_equal(3, &ts)
       assert_equal(4, &sw)
       set ts=8 sw=4
+
+      [@a, @z] = ['aa', 'zz']
+      assert_equal('aa', @a)
+      assert_equal('zz', @z)
+
+      [$SOME_VAR, $OTHER_VAR] = ['some', 'other']
+      assert_equal('some', $SOME_VAR)
+      assert_equal('other', $OTHER_VAR)
+
+      [g:globalvar, s:scriptvar, b:bufvar, w:winvar, t:tabvar, v:errmsg] =
+            ['global', 'script', 'buf', 'win', 'tab', 'error']
+      assert_equal('global', g:globalvar)
+      assert_equal('script', s:scriptvar)
+      assert_equal('buf', b:bufvar)
+      assert_equal('win', w:winvar)
+      assert_equal('tab', t:tabvar)
+      assert_equal('error', v:errmsg)
+      unlet g:globalvar
   END
   CheckDefAndScriptSuccess(lines)
 enddef
index 84571336799274db190a1ce96ec63862b790e4bf..d4023e8178d7c407f53ca76e5bbb4696ca89e0a0 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2072,
 /**/
     2071,
 /**/
index 0620be00c325208cc4a6298d8c57b3b2d5150f35..1e65239c2f556540ec83cd5ab0f7197991792fc5 100644 (file)
@@ -5123,7 +5123,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
        // can be something like "[1, 2]->func()"
        return arg;
 
-    if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen])))
+    if (oplen > 0 && (!VIM_ISWHITE(*sp) || !IS_WHITE_OR_NUL(op[oplen])))
     {
        error_white_both(op, oplen);
        return NULL;
@@ -5159,10 +5159,16 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
     }
     else if (var_count > 0)
     {
+       char_u *wp;
+
        // for "[var, var] = expr" evaluate the expression here, loop over the
        // list of variables below.
+       // A line break may follow the "=".
 
-       p = skipwhite(op + oplen);
+       wp = op + oplen;
+       p = skipwhite(wp);
+       if (may_get_next_line(wp, &p, cctx) == FAIL)
+           return FAIL;
        if (compile_expr0(&p, cctx) == FAIL)
            return NULL;
        end = p;