]> granicus.if.org Git - vim/commitdiff
patch 8.2.2066: Vim9: assignment with += doesn't work v8.2.2066
authorBram Moolenaar <Bram@vim.org>
Sat, 28 Nov 2020 20:21:17 +0000 (21:21 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 28 Nov 2020 20:21:17 +0000 (21:21 +0100)
Problem:    Vim9: assignment with += doesn't work.
Solution:   Do not see the "+" as an addition operator.

src/eval.c
src/ex_docmd.c
src/testdir/test_vim9_assign.vim
src/version.c

index f23d721df2618dace7e3cab932437fcc8c6562ec..199dc9c0a6d40c5d4b91c2c68dbe868a5095e836 100644 (file)
@@ -2769,10 +2769,11 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        int         vim9script = in_vim9script();
 
        // "." is only string concatenation when scriptversion is 1
+       // "+=" and "-=" are assignment
        p = eval_next_non_blank(*arg, evalarg, &getnext);
        op = *p;
        concat = op == '.' && (*(p + 1) == '.' || current_sctx.sc_version < 2);
-       if (op != '+' && op != '-' && !concat)
+       if ((op != '+' && op != '-' && !concat) || p[1] == '=')
            break;
 
        evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
index a06e8a89da349d8f20ba395c99cd5405ed102e5f..d530c0823a651c3e2c44608d7a0631646d4e16bf 100644 (file)
@@ -3332,9 +3332,13 @@ find_ex_command(
 
                // When followed by "=" or "+=" then it is an assignment.
                ++emsg_silent;
-               if (skip_expr(&after, NULL) == OK
-                                 && (*after == '='
-                                     || (*after != NUL && after[1] == '=')))
+               if (skip_expr(&after, NULL) == OK)
+                   after = skipwhite(after);
+               else
+                   after = (char_u *)"";
+               if (*after == '=' || (*after != NUL && after[1] == '=')
+                                        || (after[0] == '.' && after[1] == '.'
+                                                          && after[2] == '='))
                    eap->cmdidx = CMD_var;
                else
                    eap->cmdidx = CMD_eval;
index fe9fc44e1f45424a9439f253bde5073360a4ba33..2e08e8bb7e5c2f6e0819a10c0da0d515322e7a55 100644 (file)
@@ -866,18 +866,17 @@ def Test_assign_dict_unknown_type()
   END
   CheckScriptSuccess(lines)
 
-  # doesn't work yet
-  #lines =<< trim END
-  #    vim9script
-  #    var mylist = [[]]
-  #    mylist[0] += [#{one: 'one'}]
-  #    def Func()
-  #      var dd = mylist[0][0]
-  #      assert_equal('one', dd.one)
-  #    enddef
-  #    Func()
-  #END
-  #CheckScriptSuccess(lines)
+  lines =<< trim END
+      vim9script
+      var mylist = [[]]
+      mylist[0] += [#{one: 'one'}]
+      def Func()
+        var dd = mylist[0][0]
+        assert_equal('one', dd.one)
+      enddef
+      Func()
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def Test_assign_lambda()
index dac3d5cf718b04f07e10a9aa526bef5ac0ed9b28..b94f0df8009a0b3b8dc5beb1d4934d05bb9d663e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2066,
 /**/
     2065,
 /**/