]> granicus.if.org Git - vim/commitdiff
patch 8.2.1365: Vim9: no error for missing white space around operator v8.2.1365
authorBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 08:53:21 +0000 (10:53 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 5 Aug 2020 08:53:21 +0000 (10:53 +0200)
Problem:    Vim9: no error for missing white space around operator.
Solution:   Check for white space. (closes #6618)

src/eval.c
src/evalvars.c
src/proto/vim9compile.pro
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index cfa86ef2c50a8b5e9bed19a2678ddc78528c7e6d..3c4e5bdefc26bc92c4d47ac77ea665d0e265afbc 100644 (file)
@@ -2574,6 +2574,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        int         getnext;
        char_u      *p;
        int         op;
+       int         oplen;
        int         concat;
        typval_T    var2;
 
@@ -2584,11 +2585,19 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        if (op != '+' && op != '-' && !concat)
            break;
 
+       evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
        if (getnext)
            *arg = eval_next_line(evalarg);
        else
+       {
+           if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
+           {
+               error_white_both(p, 1);
+               clear_tv(rettv);
+               return FAIL;
+           }
            *arg = p;
-       evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
+       }
        if ((op != '+' || (rettv->v_type != VAR_LIST
                                                 && rettv->v_type != VAR_BLOB))
 #ifdef FEAT_FLOAT
@@ -2613,9 +2622,14 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        /*
         * Get the second variable.
         */
-       if (op == '.' && *(*arg + 1) == '.')  // .. string concatenation
-           ++*arg;
-       *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
+       oplen = (op == '.' && *(*arg + 1) == '.') ? 2 : 1;
+       if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[oplen]))
+       {
+           error_white_both(p, oplen);
+           clear_tv(rettv);
+           return FAIL;
+       }
+       *arg = skipwhite_and_linebreak(*arg + oplen, evalarg);
        if (eval6(arg, &var2, evalarg, op == '.') == FAIL)
        {
            clear_tv(rettv);
@@ -3358,6 +3372,7 @@ eval_method(
     }
     else
     {
+       *arg = skipwhite(*arg);
        if (**arg != '(')
        {
            if (verbose)
@@ -4841,7 +4856,7 @@ get_env_len(char_u **arg)
 
 /*
  * Get the length of the name of a function or internal variable.
- * "arg" is advanced to the first non-white character after the name.
+ * "arg" is advanced to after the name.
  * Return 0 if something is wrong.
  */
     int
@@ -4867,7 +4882,7 @@ get_id_len(char_u **arg)
        return 0;
 
     len = (int)(p - *arg);
-    *arg = skipwhite(p);
+    *arg = p;
 
     return len;
 }
index cf75487eaa89944809a85fdb99ddc097ecd56954..869deefc2fe675c041280c88ff00974a2e11a4c4 100644 (file)
@@ -1137,6 +1137,7 @@ list_arg_vars(exarg_T *eap, char_u *arg, int *first)
            }
            else
            {
+               arg = skipwhite(arg);
                if (tofree != NULL)
                    name = tofree;
                if (eval_variable(name, len, &tv, NULL, TRUE, FALSE) == FAIL)
@@ -3358,6 +3359,7 @@ assert_error(garray_T *gap)
     int
 var_exists(char_u *var)
 {
+    char_u     *arg = var;
     char_u     *name;
     char_u     *tofree;
     typval_T    tv;
@@ -3366,7 +3368,7 @@ var_exists(char_u *var)
 
     // get_name_len() takes care of expanding curly braces
     name = var;
-    len = get_name_len(&var, &tofree, TRUE, FALSE);
+    len = get_name_len(&arg, &tofree, TRUE, FALSE);
     if (len > 0)
     {
        if (tofree != NULL)
@@ -3375,12 +3377,13 @@ var_exists(char_u *var)
        if (n)
        {
            // handle d.key, l[idx], f(expr)
-           n = (handle_subscript(&var, &tv, &EVALARG_EVALUATE, FALSE) == OK);
+           arg = skipwhite(arg);
+           n = (handle_subscript(&arg, &tv, &EVALARG_EVALUATE, FALSE) == OK);
            if (n)
                clear_tv(&tv);
        }
     }
-    if (*var != NUL)
+    if (*arg != NUL)
        n = FALSE;
 
     vim_free(tofree);
index fd2dd1bf4b3393b28319a96c58d4abce5339d988..14f9bbc7b2b14a3c8cf4502a91cc70cb30d1b0df 100644 (file)
@@ -17,6 +17,7 @@ char_u *peek_next_line_from_context(cctx_T *cctx);
 char_u *next_line_from_context(cctx_T *cctx, int skip_comment);
 char_u *to_name_const_end(char_u *arg);
 exptype_T get_compare_type(char_u *p, int *len, int *type_is);
+void error_white_both(char_u *op, int len);
 int assignment_len(char_u *p, int *heredoc);
 void vim9_declare_error(char_u *name);
 int check_vim9_unlet(char_u *name);
index 584126ff1e7a9ae28f469b47c01ddf666365c51e..7e53a287d5ca099f42cbd8ea590008e47acbc46d 100644 (file)
@@ -872,6 +872,39 @@ def Test_expr5_vim9script()
       echo 'abc' isnot? 'abc'
   END
   CheckScriptFailure(lines, 'E15:')
+
+  # check white space
+  lines =<< trim END
+      vim9script
+      echo 5+6
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      echo 5 +6
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      echo 5+ 6
+  END
+  CheckScriptFailure(lines, 'E1004:')
+
+  lines =<< trim END
+      vim9script
+      echo 'a'..'b'
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      echo 'a' ..'b'
+  END
+  CheckScriptFailure(lines, 'E1004:')
+  lines =<< trim END
+      vim9script
+      echo 'a'.. 'b'
+  END
+  CheckScriptFailure(lines, 'E1004:')
 enddef
 
 def Test_expr5_float()
index f3fc4c7bee4d06c0a449e59b23ceeec35865fed6..d0248369ce324707998e4b729746d5d7defaa7be 100644 (file)
@@ -1270,7 +1270,7 @@ enddef
 def TreeWalk(dir: string): list<any>
   return readdir(dir)->map({_, val ->
             fnamemodify(dir .. '/' .. val, ':p')->isdirectory()
-               ? {val : TreeWalk(dir .. '/' .. val)}
+               ? {val: TreeWalk(dir .. '/' .. val)}
                : val
              })
 enddef
index 366d3ab7775182aff996b51a10088f3b0f1e38c7..112a502e483539ceecb0ac693ca4251926af21e1 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1365,
 /**/
     1364,
 /**/
index 24ef87931b83a1999b604f6f11c9844fceb4be1b..f8381d7837d3bc39d85e2b25a1436731999a8181 100644 (file)
@@ -4243,6 +4243,18 @@ compile_expr7(
     return OK;
 }
 
+/*
+ * Give the "white on both sides" error, taking the operator from "p[len]".
+ */
+    void
+error_white_both(char_u *op, int len)
+{
+    char_u     buf[10];
+
+    vim_strncpy(buf, op, len);
+    semsg(_(e_white_both), buf);
+}
+
 /*
  *     *       number multiplication
  *     /       number division
@@ -4275,10 +4287,7 @@ compile_expr6(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
 
        if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[1]))
        {
-           char_u buf[3];
-
-           vim_strncpy(buf, op, 1);
-           semsg(_(e_white_both), buf);
+           error_white_both(op, 1);
            return FAIL;
        }
        *arg = skipwhite(op + 1);
@@ -4354,10 +4363,7 @@ compile_expr5(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
 
        if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(op[oplen]))
        {
-           char_u buf[3];
-
-           vim_strncpy(buf, op, oplen);
-           semsg(_(e_white_both), buf);
+           error_white_both(op, oplen);
            return FAIL;
        }
 
@@ -4486,10 +4492,7 @@ compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
 
        if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[len]))
        {
-           char_u buf[7];
-
-           vim_strncpy(buf, p, len);
-           semsg(_(e_white_both), buf);
+           error_white_both(p, len);
            return FAIL;
        }
 
@@ -5132,10 +5135,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
 
     if (oplen > 0 && (!VIM_ISWHITE(*sp) || !VIM_ISWHITE(op[oplen])))
     {
-       char_u  buf[4];
-
-       vim_strncpy(buf, op, oplen);
-       semsg(_(e_white_both), buf);
+       error_white_both(op, oplen);
        return NULL;
     }