]> granicus.if.org Git - vim/commitdiff
patch 8.2.1890: Vim9: strange error for subtracting from a list v8.2.1890
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Oct 2020 18:09:43 +0000 (20:09 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Oct 2020 18:09:43 +0000 (20:09 +0200)
Problem:    Vim9: strange error for subtracting from a list.
Solution:   Check getting a number, not a string. (closes #7167)

src/eval.c
src/testdir/test_vim9_expr.vim
src/version.c

index 9ef3128638b7da8dfbb42f0534b1706bb1e8019c..bb402dee94d042b19ce2e8c88977b201b2fecfcc 100644 (file)
@@ -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)
 {
@@ -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)
 {
@@ -2777,8 +2783,10 @@ 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.
@@ -2786,7 +2794,9 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
            // 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;
index 9b5b4ff2e41a44f811375cfd058c5cba77094b51..568c3bf6a4a7417ff696bf9b7c9f20b93050a94a 100644 (file)
@@ -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
index 97f9cba2fcc124e54141a7c338b221f6a39b76e1..2340ab8d1fd5ffd4827bf9b5e127b70ce4ee8083 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1890,
 /**/
     1889,
 /**/