mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2796: Vim9: redir to variable does not accept an index
Problem: Vim9: redir to variable does not accept an index. Solution: Make the index work.
This commit is contained in:
@@ -1212,10 +1212,35 @@ def Test_redir_to_var()
|
|||||||
redir END
|
redir END
|
||||||
assert_equal("\nsomething\nmore", result)
|
assert_equal("\nsomething\nmore", result)
|
||||||
|
|
||||||
|
var d: dict<string>
|
||||||
|
redir => d.redir
|
||||||
|
echo 'dict'
|
||||||
|
redir END
|
||||||
|
assert_equal({redir: "\ndict"}, d)
|
||||||
|
|
||||||
|
var l = ['a', 'b', 'c']
|
||||||
|
redir => l[1]
|
||||||
|
echo 'list'
|
||||||
|
redir END
|
||||||
|
assert_equal(['a', "\nlist", 'c'], l)
|
||||||
|
|
||||||
|
var dl = {l: ['x']}
|
||||||
|
redir => dl.l[0]
|
||||||
|
echo 'dict-list'
|
||||||
|
redir END
|
||||||
|
assert_equal({l: ["\ndict-list"]}, dl)
|
||||||
|
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
redir => notexist
|
redir => notexist
|
||||||
END
|
END
|
||||||
CheckDefFailure(lines, 'E1089:')
|
CheckDefFailure(lines, 'E1089:')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var ls = 'asdf'
|
||||||
|
redir => ls[1]
|
||||||
|
redir END
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1141:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2796,
|
||||||
/**/
|
/**/
|
||||||
2795,
|
2795,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -134,10 +134,14 @@ typedef enum {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
assign_dest_T lhs_dest; // type of destination
|
assign_dest_T lhs_dest; // type of destination
|
||||||
|
|
||||||
char_u *lhs_name; // allocated name including
|
char_u *lhs_name; // allocated name excluding the last
|
||||||
// "[expr]" or ".name".
|
// "[expr]" or ".name".
|
||||||
size_t lhs_varlen; // length of the variable without
|
size_t lhs_varlen; // length of the variable without
|
||||||
// "[expr]" or ".name"
|
// "[expr]" or ".name"
|
||||||
|
char_u *lhs_whole; // allocated name including the last
|
||||||
|
// "[expr]" or ".name" for :redir
|
||||||
|
size_t lhs_varlen_total; // length of the variable including
|
||||||
|
// any "[expr]" or ".name"
|
||||||
char_u *lhs_dest_end; // end of the destination, including
|
char_u *lhs_dest_end; // end of the destination, including
|
||||||
// "[expr]" or ".name".
|
// "[expr]" or ".name".
|
||||||
|
|
||||||
@@ -5845,6 +5849,7 @@ compile_lhs(
|
|||||||
|
|
||||||
// compute the length of the destination without "[expr]" or ".name"
|
// compute the length of the destination without "[expr]" or ".name"
|
||||||
lhs->lhs_varlen = var_end - var_start;
|
lhs->lhs_varlen = var_end - var_start;
|
||||||
|
lhs->lhs_varlen_total = lhs->lhs_varlen;
|
||||||
lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen);
|
lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen);
|
||||||
if (lhs->lhs_name == NULL)
|
if (lhs->lhs_name == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -6073,7 +6078,10 @@ compile_lhs(
|
|||||||
{
|
{
|
||||||
p = skip_index(after);
|
p = skip_index(after);
|
||||||
if (*p != '[' && *p != '.')
|
if (*p != '[' && *p != '.')
|
||||||
|
{
|
||||||
|
lhs->lhs_varlen_total = p - var_start;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
after = p;
|
after = p;
|
||||||
}
|
}
|
||||||
if (after > var_start + lhs->lhs_varlen)
|
if (after > var_start + lhs->lhs_varlen)
|
||||||
@@ -8592,17 +8600,17 @@ compile_substitute(char_u *arg, exarg_T *eap, cctx_T *cctx)
|
|||||||
compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
|
compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
|
||||||
{
|
{
|
||||||
char_u *arg = eap->arg;
|
char_u *arg = eap->arg;
|
||||||
|
lhs_T *lhs = &cctx->ctx_redir_lhs;
|
||||||
|
|
||||||
if (cctx->ctx_redir_lhs.lhs_name != NULL)
|
if (lhs->lhs_name != NULL)
|
||||||
{
|
{
|
||||||
if (STRNCMP(arg, "END", 3) == 0)
|
if (STRNCMP(arg, "END", 3) == 0)
|
||||||
{
|
{
|
||||||
if (cctx->ctx_redir_lhs.lhs_append)
|
if (lhs->lhs_append)
|
||||||
{
|
{
|
||||||
if (compile_load_lhs(&cctx->ctx_redir_lhs,
|
if (compile_load_lhs(lhs, lhs->lhs_name, NULL, cctx) == FAIL)
|
||||||
cctx->ctx_redir_lhs.lhs_name, NULL, cctx) == FAIL)
|
|
||||||
return NULL;
|
return NULL;
|
||||||
if (cctx->ctx_redir_lhs.lhs_has_index)
|
if (lhs->lhs_has_index)
|
||||||
emsg("redir with index not implemented yet");
|
emsg("redir with index not implemented yet");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8610,13 +8618,22 @@ compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
|
|||||||
// in the variable.
|
// in the variable.
|
||||||
generate_instr_type(cctx, ISN_REDIREND, &t_string);
|
generate_instr_type(cctx, ISN_REDIREND, &t_string);
|
||||||
|
|
||||||
if (cctx->ctx_redir_lhs.lhs_append)
|
if (lhs->lhs_append)
|
||||||
generate_instr_drop(cctx, ISN_CONCAT, 1);
|
generate_instr_drop(cctx, ISN_CONCAT, 1);
|
||||||
|
|
||||||
if (generate_store_lhs(cctx, &cctx->ctx_redir_lhs, -1) == FAIL)
|
if (lhs->lhs_has_index)
|
||||||
|
{
|
||||||
|
// Use the info in "lhs" to store the value at the index in the
|
||||||
|
// list or dict.
|
||||||
|
if (compile_assign_unlet(lhs->lhs_whole, lhs, TRUE,
|
||||||
|
&t_string, cctx) == FAIL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
else if (generate_store_lhs(cctx, lhs, -1) == FAIL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
VIM_CLEAR(cctx->ctx_redir_lhs.lhs_name);
|
VIM_CLEAR(lhs->lhs_name);
|
||||||
|
VIM_CLEAR(lhs->lhs_whole);
|
||||||
return arg + 3;
|
return arg + 3;
|
||||||
}
|
}
|
||||||
emsg(_(e_cannot_nest_redir));
|
emsg(_(e_cannot_nest_redir));
|
||||||
@@ -8636,13 +8653,19 @@ compile_redir(char_u *line, exarg_T *eap, cctx_T *cctx)
|
|||||||
}
|
}
|
||||||
arg = skipwhite(arg);
|
arg = skipwhite(arg);
|
||||||
|
|
||||||
if (compile_assign_lhs(arg, &cctx->ctx_redir_lhs, CMD_redir,
|
if (compile_assign_lhs(arg, lhs, CMD_redir,
|
||||||
FALSE, FALSE, 1, cctx) == FAIL)
|
FALSE, FALSE, 1, cctx) == FAIL)
|
||||||
return NULL;
|
return NULL;
|
||||||
generate_instr(cctx, ISN_REDIRSTART);
|
generate_instr(cctx, ISN_REDIRSTART);
|
||||||
cctx->ctx_redir_lhs.lhs_append = append;
|
lhs->lhs_append = append;
|
||||||
|
if (lhs->lhs_has_index)
|
||||||
|
{
|
||||||
|
lhs->lhs_whole = vim_strnsave(arg, lhs->lhs_varlen_total);
|
||||||
|
if (lhs->lhs_whole == NULL)
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return arg + cctx->ctx_redir_lhs.lhs_varlen;
|
return arg + lhs->lhs_varlen_total;
|
||||||
}
|
}
|
||||||
|
|
||||||
// other redirects are handled like at script level
|
// other redirects are handled like at script level
|
||||||
@@ -9335,6 +9358,7 @@ erret:
|
|||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
}
|
}
|
||||||
vim_free(cctx.ctx_redir_lhs.lhs_name);
|
vim_free(cctx.ctx_redir_lhs.lhs_name);
|
||||||
|
vim_free(cctx.ctx_redir_lhs.lhs_whole);
|
||||||
}
|
}
|
||||||
|
|
||||||
current_sctx = save_current_sctx;
|
current_sctx = save_current_sctx;
|
||||||
|
Reference in New Issue
Block a user