changeset 22683:5cbcd3768125 v8.2.1890

patch 8.2.1890: Vim9: strange error for subtracting from a list Commit: https://github.com/vim/vim/commit/081db1a66d17e46ac3b03b7514f11a004a35009a Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 22 20:09:43 2020 +0200 patch 8.2.1890: Vim9: strange error for subtracting from a list Problem: Vim9: strange error for subtracting from a list. Solution: Check getting a number, not a string. (closes https://github.com/vim/vim/issues/7167)
author Bram Moolenaar <Bram@vim.org>
date Thu, 22 Oct 2020 20:15:03 +0200
parents 42790e1a64a9
children 3d1331314be7
files src/eval.c src/testdir/test_vim9_expr.vim src/version.c
diffstat 3 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/eval.c
+++ b/src/eval.c
@@ -2679,6 +2679,9 @@ eval4(char_u **arg, typval_T *rettv, eva
     return OK;
 }
 
+/*
+ * Make a copy of blob "tv1" and append blob "tv2".
+ */
     void
 eval_addblob(typval_T *tv1, typval_T *tv2)
 {
@@ -2699,6 +2702,9 @@ eval_addblob(typval_T *tv1, typval_T *tv
     }
 }
 
+/*
+ * Make a copy of list "tv1" and append list "tv2".
+ */
     int
 eval_addlist(typval_T *tv1, typval_T *tv2)
 {
@@ -2777,8 +2783,10 @@ eval5(char_u **arg, typval_T *rettv, eva
 #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.
@@ -2786,7 +2794,9 @@ eval5(char_u **arg, typval_T *rettv, eva
 	    // 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;
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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
--- 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 */
 /**/
+    1890,
+/**/
     1889,
 /**/
     1888,