Patch 8.2.2798
Problem: Vim9: redir to variable with append does not accept an index.
Solution: Make the appending work.
Files: src/vim9compile.c, src/testdir/test_vim9_cmd.vim
*** ../vim-8.2.2797/src/vim9compile.c 2021-04-21 14:24:20.691270626 +0200
--- src/vim9compile.c 2021-04-21 15:55:21.867667620 +0200
***************
*** 6250,6255 ****
--- 6250,6286 ----
}
/*
+ * 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,6562 ****
// 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;
! }
}
// Compile the expression. Temporarily hide the new local
--- 6566,6574 ----
// for "+=", "*=", "..=" etc. first load the current value
if (*op != '=')
{
! if (compile_load_lhs_with_index(&lhs, var_start,
! cctx) == FAIL)
! goto theend;
}
// Compile the expression. Temporarily hide the new local
***************
*** 8608,8617 ****
{
if (lhs->lhs_append)
{
! if (compile_load_lhs(lhs, lhs->lhs_name, NULL, 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
--- 8620,8629 ----
{
if (lhs->lhs_append)
{
! // First load the current variable value.
! if (compile_load_lhs_with_index(lhs, lhs->lhs_whole,
! cctx) == FAIL)
return NULL;
}
// Gets the redirected text and put it on the stack, then store it
*** ../vim-8.2.2797/src/testdir/test_vim9_cmd.vim 2021-04-21 14:24:20.695270608 +0200
--- src/testdir/test_vim9_cmd.vim 2021-04-21 15:54:53.543599319 +0200
***************
*** 1230,1235 ****
--- 1230,1240 ----
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
*** ../vim-8.2.2797/src/version.c 2021-04-21 15:11:18.153623383 +0200
--- src/version.c 2021-04-21 15:54:14.035489905 +0200
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2798,
/**/
--
Amazing but true: If all the salmon caught in Canada in one year were laid
end to end across the Sahara Desert, the smell would be absolutely awful.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///