1
0
forked from aniani/vim

patch 8.2.2806: Vim9: using "++nr" as a command might not work

Problem:    Vim9: using "++nr" as a command might not work.
Solution:   Do not recognize "++" and "--" in a following line as addition or
            subtraction.
This commit is contained in:
Bram Moolenaar
2021-04-24 19:08:24 +02:00
parent 96cf4ba8fb
commit bdc0f1c698
10 changed files with 97 additions and 27 deletions

View File

@@ -4688,6 +4688,10 @@ compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
op = may_peek_next_line(cctx, *arg, &next);
if (*op != '+' && *op != '-' && !(*op == '.' && *(op + 1) == '.'))
break;
if (op[0] == op[1] && *op != '.' && next)
// Finding "++" or "--" on the next line is a separate command.
// But ".." is concatenation.
break;
oplen = (*op == '.' ? 2 : 1);
if (next != NULL)
{
@@ -6395,6 +6399,7 @@ compile_assign_unlet(
* "const name = expr"
* "name = expr"
* "arg" points to "name".
* "++arg" and "--arg"
* Return NULL for an error.
* Return "arg" if it does not look like a variable list.
*/
@@ -6413,6 +6418,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
char_u *op;
int oplen = 0;
int heredoc = FALSE;
int incdec = FALSE;
type_T *rhs_type = &t_any;
char_u *sp;
int is_decl = is_decl_command(cmdidx);
@@ -6447,6 +6453,12 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
error_white_both(op, oplen);
return NULL;
}
if (eap->cmdidx == CMD_increment || eap->cmdidx == CMD_decrement)
{
op = (char_u *)(eap->cmdidx == CMD_increment ? "+=" : "-=");
oplen = 2;
incdec = TRUE;
}
if (heredoc)
{
@@ -6571,23 +6583,31 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
goto theend;
}
// Compile the expression. Temporarily hide the new local
// variable here, it is not available to this expression.
if (lhs.lhs_new_local)
--cctx->ctx_locals.ga_len;
// Compile the expression.
instr_count = instr->ga_len;
wp = op + oplen;
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
if (incdec)
{
r = generate_PUSHNR(cctx, 1);
}
else
{
// Temporarily hide the new local variable here, it is
// not available to this expression.
if (lhs.lhs_new_local)
--cctx->ctx_locals.ga_len;
wp = op + oplen;
if (may_get_next_line_error(wp, &p, cctx) == FAIL)
{
if (lhs.lhs_new_local)
++cctx->ctx_locals.ga_len;
goto theend;
}
r = compile_expr0_ext(&p, cctx, &is_const);
if (lhs.lhs_new_local)
++cctx->ctx_locals.ga_len;
goto theend;
if (r == FAIL)
goto theend;
}
r = compile_expr0_ext(&p, cctx, &is_const);
if (lhs.lhs_new_local)
++cctx->ctx_locals.ga_len;
if (r == FAIL)
goto theend;
}
else if (semicolon && var_idx == var_count - 1)
{
@@ -9018,9 +9038,11 @@ compile_def_function(
/*
* COMMAND after range
* 'text'->func() should not be confused with 'a mark
* "++nr" and "--nr" are eval commands
*/
cmd = ea.cmd;
if (*cmd != '\'' || starts_with_colon)
if (starts_with_colon || !(*cmd == '\''
|| (cmd[0] == cmd[1] && (*cmd == '+' || *cmd == '-'))))
{
ea.cmd = skip_range(ea.cmd, TRUE, NULL);
if (ea.cmd > cmd)
@@ -9125,6 +9147,8 @@ compile_def_function(
case CMD_var:
case CMD_final:
case CMD_const:
case CMD_increment:
case CMD_decrement:
line = compile_assignment(p, &ea, ea.cmdidx, &cctx);
if (line == p)
line = NULL;