]> granicus.if.org Git - vim/commitdiff
patch 8.2.1372: Vim9: no error for missing white space around operator v8.2.1372
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 10:44:41 +0000 (12:44 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 10:44:41 +0000 (12:44 +0200)
Problem:    Vim9: no error for missing white space around operator.
Solution:   Check for white space around ? and :.

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

index a9c36ac38c11536d563ac1dafb60f2e4f648c611..a7f6086ef66ba851a5f7f888fd7b630ef6f543fe 100644 (file)
@@ -2072,7 +2072,7 @@ eval0(
  *     expr2 ? expr1 : expr1
  *
  * "arg" must point to the first non-white of the expression.
- * "arg" is advanced to the next non-white after the recognized expression.
+ * "arg" is advanced to just after the recognized expression.
  *
  * Note: "rettv.v_lock" is not set.
  *
@@ -2111,7 +2111,15 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        if (getnext)
            *arg = eval_next_line(evalarg_used);
        else
+       {
+           if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
+           {
+               error_white_both(p, 1);
+               clear_tv(rettv);
+               return FAIL;
+           }
            *arg = p;
+       }
 
        result = FALSE;
        if (evaluate)
@@ -2128,6 +2136,12 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        /*
         * Get the second variable.  Recursive!
         */
+       if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
+       {
+           error_white_both(p, 1);
+           clear_tv(rettv);
+           return FAIL;
+       }
        *arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
        evalarg_used->eval_flags = result ? orig_flags
                                                 : orig_flags & ~EVAL_EVALUATE;
@@ -2148,11 +2162,25 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        if (getnext)
            *arg = eval_next_line(evalarg_used);
        else
+       {
+           if (evaluate && in_vim9script() && !VIM_ISWHITE(p[-1]))
+           {
+               error_white_both(p, 1);
+               clear_tv(rettv);
+               return FAIL;
+           }
            *arg = p;
+       }
 
        /*
         * Get the third variable.  Recursive!
         */
+       if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[1]))
+       {
+           error_white_both(p, 1);
+           clear_tv(rettv);
+           return FAIL;
+       }
        *arg = skipwhite_and_linebreak(*arg + 1, evalarg_used);
        evalarg_used->eval_flags = !result ? orig_flags
                                                 : orig_flags & ~EVAL_EVALUATE;
@@ -2179,7 +2207,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
  *     expr2 || expr2 || expr2     logical OR
  *
  * "arg" must point to the first non-white of the expression.
- * "arg" is advanced to the next non-white after the recognized expression.
+ * "arg" is advanced to just after the recognized expression.
  *
  * Return OK or FAIL.
  */
@@ -2310,7 +2338,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
  *     expr3 && expr3 && expr3     logical AND
  *
  * "arg" must point to the first non-white of the expression.
- * "arg" is advanced to the next non-white after the recognized expression.
+ * "arg" is advanced to just after the recognized expression.
  *
  * Return OK or FAIL.
  */
index 70813377b561171df9eef88bb3692f794496eda0..8be0dea36e78b84369d33761d5070575b6a195d1 100644 (file)
@@ -60,7 +60,7 @@ def Test_expr1()
 enddef
 
 def Test_expr1_vimscript()
-  # only checks line continuation
+  # check line continuation
   let lines =<< trim END
       vim9script
       let var = 1
@@ -87,6 +87,33 @@ def Test_expr1_vimscript()
       assert_equal('no', var)
   END
   CheckScriptSuccess(lines)
+
+  # check white space
+  lines =<< trim END
+      vim9script
+      let var = v:true?1:2
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      let var = v:true? 1 : 2
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      let var = v:true ?1 : 2
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      let var = v:true ? 1: 2
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      let var = v:true ? 1 :2
+  END
+  CheckScriptFailure(lines, 'E1004:')
 enddef
 
 func Test_expr1_fails()
index 9d06cd20e3efb6d2175b4af53fe497e9891982c9..1e23a08ad609dd16b6d3bff6e1fd04a7a4c4ee0e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1372,
 /**/
     1371,
 /**/