summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-04-21 16:00:10 +0200
committerBram Moolenaar <Bram@vim.org>2021-04-21 16:00:10 +0200
commita369c3d9c1217cd932bc3d1751a8cff1f5aef1e4 (patch)
treeff7aea5fa5c0882b688d4a6ee070849606b659a8
parent2d5f385cee3668c44089edcb9d60b0b5d751ee5d (diff)
downloadvim-git-a369c3d9c1217cd932bc3d1751a8cff1f5aef1e4.tar.gz
patch 8.2.2798: Vim9: redir to variable with append does not accept an indexv8.2.2798
Problem: Vim9: redir to variable with append does not accept an index. Solution: Make the appending work.
-rw-r--r--src/testdir/test_vim9_cmd.vim5
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c62
3 files changed, 44 insertions, 25 deletions
diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim
index ddf3df2a4..ab2ad6788 100644
--- a/src/testdir/test_vim9_cmd.vim
+++ b/src/testdir/test_vim9_cmd.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 3547ef437..1420e7bda 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2798,
+/**/
2797,
/**/
2796,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index d6ea322d3..c74bb6e5c 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -6250,6 +6250,37 @@ compile_load_lhs(
}
/*
+ * 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".
* Returns OK or FAIL.
@@ -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