]> granicus.if.org Git - vim/commitdiff
patch 8.2.2798: Vim9: redir to variable with append does not accept an index v8.2.2798
authorBram Moolenaar <Bram@vim.org>
Wed, 21 Apr 2021 14:00:10 +0000 (16:00 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 21 Apr 2021 14:00:10 +0000 (16:00 +0200)
Problem:    Vim9: redir to variable with append does not accept an index.
Solution:   Make the appending work.

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

index ddf3df2a4d7c26565f489fc5317be7d6f6f5276b..ab2ad6788ad1c5a2f3eefe96402d759c6d2a1700 100644 (file)
@@ -1230,6 +1230,11 @@ def Test_redir_to_var()
   redir END
   assert_equal({l: ["\ndict-list"]}, dl)
 
+  redir =>> d.redir
+    echo 'more'
+  redir END
+  assert_equal({redir: "\ndict\nmore"}, d)
+
   var lines =<< trim END
     redir => notexist
   END
index 3547ef4379f31204d6feff5ab40eaa8bdd114c58..1420e7bdae8dcf3b574c71a93e97dae141af67a8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2798,
 /**/
     2797,
 /**/
index d6ea322d3f26bef479b8f9a04f3e0b5e8baea7a1..c74bb6e5cd41f74ef6575de6ebdb652a5e4633fa 100644 (file)
@@ -6249,6 +6249,37 @@ compile_load_lhs(
     return OK;
 }
 
+/*
+ * Produce code for loading "lhs" and also take care of an index.
+ * Return OK/FAIL.
+ */
+    static int
+compile_load_lhs_with_index(lhs_T *lhs, char_u *var_start, cctx_T *cctx)
+{
+    compile_load_lhs(lhs, var_start, NULL, cctx);
+
+    if (lhs->lhs_has_index)
+    {
+       int range = FALSE;
+
+       // Get member from list or dict.  First compile the
+       // index value.
+       if (compile_assign_index(var_start, lhs, &range, cctx) == FAIL)
+           return FAIL;
+       if (range)
+       {
+           semsg(_(e_cannot_use_range_with_assignment_operator_str),
+                                                                   var_start);
+           return FAIL;
+       }
+
+       // Get the member.
+       if (compile_member(FALSE, cctx) == FAIL)
+           return FAIL;
+    }
+    return OK;
+}
+
 /*
  * Assignment to a list or dict member, or ":unlet" for the item, using the
  * information in "lhs".
@@ -6535,28 +6566,9 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                    // for "+=", "*=", "..=" etc. first load the current value
                    if (*op != '=')
                    {
-                       compile_load_lhs(&lhs, var_start, NULL, cctx);
-
-                       if (lhs.lhs_has_index)
-                       {
-                           int range = FALSE;
-
-                           // Get member from list or dict.  First compile the
-                           // index value.
-                           if (compile_assign_index(var_start, &lhs,
-                                                        &range, cctx) == FAIL)
-                               goto theend;
-                           if (range)
-                           {
-                               semsg(_(e_cannot_use_range_with_assignment_operator_str),
-                                                                   var_start);
-                               goto theend;
-                           }
-
-                           // Get the member.
-                           if (compile_member(FALSE, cctx) == FAIL)
-                               goto theend;
-                       }
+                       if (compile_load_lhs_with_index(&lhs, var_start,
+                                                                cctx) == FAIL)
+                           goto theend;
                    }
 
                    // Compile the expression.  Temporarily hide the new local
@@ -8608,10 +8620,10 @@ compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
        {
            if (lhs->lhs_append)
            {
-               if (compile_load_lhs(lhs, lhs->lhs_name, NULL, cctx) == FAIL)
+               // First load the current variable value.
+               if (compile_load_lhs_with_index(lhs, lhs->lhs_whole,
+                                                                cctx) == FAIL)
                    return NULL;
-               if (lhs->lhs_has_index)
-                   emsg("redir with index not implemented yet");
            }
 
            // Gets the redirected text and put it on the stack, then store it