Skip to content

Commit

Permalink
patch 8.2.1890: Vim9: strange error for subtracting from a list
Browse files Browse the repository at this point in the history
Problem:    Vim9: strange error for subtracting from a list.
Solution:   Check getting a number, not a string. (closes vim#7167)
  • Loading branch information
brammool committed Oct 22, 2020
1 parent b07a39d commit 081db1a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -2679,6 +2679,9 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
return OK;
}

/*
* Make a copy of blob "tv1" and append blob "tv2".
*/
void
eval_addblob(typval_T *tv1, typval_T *tv2)
{
Expand All @@ -2699,6 +2702,9 @@ eval_addblob(typval_T *tv1, typval_T *tv2)
}
}

/*
* Make a copy of list "tv1" and append list "tv2".
*/
int
eval_addlist(typval_T *tv1, typval_T *tv2)
{
Expand Down Expand Up @@ -2777,16 +2783,20 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
#ifdef FEAT_FLOAT
&& (op == '.' || rettv->v_type != VAR_FLOAT)
#endif
)
&& evaluate)
{
int error = FALSE;

// For "list + ...", an illegal use of the first operand as
// a number cannot be determined before evaluating the 2nd
// operand: if this is also a list, all is ok.
// For "something . ...", "something - ..." or "non-list + ...",
// we know that the first operand needs to be a string or number
// without evaluating the 2nd operand. So check before to avoid
// side effects after an error.
if (evaluate && tv_get_string_chk(rettv) == NULL)
if (op != '.')
tv_get_number_chk(rettv, &error);
if ((op == '.' && tv_get_string_chk(rettv) == NULL) || error)
{
clear_tv(rettv);
return FAIL;
Expand Down
14 changes: 13 additions & 1 deletion src/testdir/test_vim9_expr.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,19 @@ def Test_expr5_vim9script()
vim9script
echo {} - 22
END
CheckScriptFailure(lines, 'E731:', 2)
CheckScriptFailure(lines, 'E728:', 2)

lines =<< trim END
vim9script
echo [] - 33
END
CheckScriptFailure(lines, 'E745:', 2)

lines =<< trim END
vim9script
echo 0z1234 - 44
END
CheckScriptFailure(lines, 'E974:', 2)

lines =<< trim END
vim9script
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1890,
/**/
1889,
/**/
Expand Down

0 comments on commit 081db1a

Please sign in to comment.