]> granicus.if.org Git - vim/commitdiff
patch 8.2.2895: Vim9: random characters appear in some error messages v8.2.2895
authormityu <mityu.mail@gmail.com>
Fri, 28 May 2021 15:52:40 +0000 (17:52 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 28 May 2021 15:52:40 +0000 (17:52 +0200)
Problem:    Vim9: random characters appear in some error messages.
Solution:   Pass the correct pointer. (closes #8277)

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

index f75263d9e8c0b8390d24cc88c5baf4b5451f2051..008b032cefc935f9988826f72d3f167733345db3 100644 (file)
@@ -2358,7 +2358,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
            ++*arg;
        if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
        {
-           error_white_both(p, op_falsy ? 2 : 1);
+           error_white_both(*arg - (op_falsy ? 1 : 0), op_falsy ? 2 : 1);
            clear_tv(rettv);
            return FAIL;
        }
@@ -2406,7 +2406,7 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
             */
            if (evaluate && vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
            {
-               error_white_both(p, 1);
+               error_white_both(*arg, 1);
                clear_tv(rettv);
                evalarg_used->eval_flags = orig_flags;
                return FAIL;
@@ -2511,7 +2511,7 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
             */
            if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2]))
            {
-               error_white_both(p, 2);
+               error_white_both(*arg, 2);
                clear_tv(rettv);
                return FAIL;
            }
@@ -2637,7 +2637,7 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
             */
            if (evaluate && in_vim9script() && !IS_WHITE_OR_NUL((*arg)[2]))
            {
-               error_white_both(p, 2);
+               error_white_both(*arg, 2);
                clear_tv(rettv);
                return FAIL;
            }
@@ -2735,10 +2735,13 @@ eval4(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
                                   ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
 
        if (getnext)
+       {
            *arg = eval_next_line(evalarg);
+           p = *arg;
+       }
        else if (evaluate && vim9script && !VIM_ISWHITE(**arg))
        {
-           error_white_both(p, len);
+           error_white_both(*arg, len);
            clear_tv(rettv);
            return FAIL;
        }
@@ -2898,7 +2901,7 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        {
            if (evaluate && vim9script && !VIM_ISWHITE(**arg))
            {
-               error_white_both(p, oplen);
+               error_white_both(*arg, oplen);
                clear_tv(rettv);
                return FAIL;
            }
@@ -3130,7 +3133,7 @@ eval6(
        {
            if (evaluate && in_vim9script() && !VIM_ISWHITE(**arg))
            {
-               error_white_both(p, 1);
+               error_white_both(*arg, 1);
                clear_tv(rettv);
                return FAIL;
            }
index f1762d7d0b5ae2efadbbb5591157e8738540ecd8..22186808e47ec24dc2522103016d0536764035e3 100644 (file)
@@ -172,11 +172,23 @@ func Test_expr1_trinary_fails()
   call CheckDefAndScriptFailure(["var x = 1? 'one' : 'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1 ?'one' : 'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1?'one' : 'two'"], msg, 1)
+  let lines =<< trim END
+    var x = 1
+     ?'one' : 'two'
+     # comment
+  END
+  call CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''?'' at "?''one'' : ''two''"', 2)
 
   let msg = "White space required before and after ':'"
   call CheckDefAndScriptFailure(["var x = 1 ? 'one': 'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1 ? 'one' :'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1 ? 'one':'two'"], msg, 1)
+  let lines =<< trim END
+    var x = 1 ? 'one'
+          :'two'
+          # Comment
+  END
+  call CheckDefAndScriptFailure(lines, 'E1004: White space required before and after '':'' at ":''two''"', 2)
 
   call CheckDefAndScriptFailure(["var x = 'x' ? 'one' : 'two'"], 'E1135:', 1)
   call CheckDefAndScriptFailure(["var x = 0z1234 ? 'one' : 'two'"], 'E974:', 1)
@@ -229,6 +241,12 @@ def Test_expr1_falsy()
   call CheckDefAndScriptFailure(["var x = 1?? 'one' : 'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1 ??'one' : 'two'"], msg, 1)
   call CheckDefAndScriptFailure(["var x = 1??'one' : 'two'"], msg, 1)
+  lines =<< trim END
+    var x = 1
+      ??'one' : 'two'
+      #comment
+  END
+  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''??'' at "??''one'' : ''two''"', 2)
 enddef
 
 def Record(val: any): any
@@ -376,6 +394,13 @@ def Test_expr2_fails()
 
   call CheckDefAndScriptFailure2(["var x = [] || false"], 'E1012: Type mismatch; expected bool but got list<unknown>', 'E745:', 1)
 
+  var lines =<< trim END
+    vim9script
+    echo false
+      ||true
+    # comment
+  END
+  CheckScriptFailure(lines, 'E1004: White space required before and after ''||'' at "||true"', 3)
 enddef
 
 " test &&
@@ -476,13 +501,19 @@ def Test_expr3_fails()
   CheckDefAndScriptFailure(["var x = 1&&2"], msg, 1)
   CheckDefAndScriptFailure(["var x = 1 &&2"], msg, 1)
   CheckDefAndScriptFailure(["var x = 1&& 2"], msg, 1)
+  var lines =<< trim END
+    var x = 1
+      &&2
+    # comment
+  END
+  CheckDefAndScriptFailure(lines, 'E1004: White space required before and after ''&&'' at "&&2"', 2)
 
   g:vals = []
   CheckDefAndScriptFailure2(["if 'yes' && 0", 'echo 0', 'endif'], 'E1012: Type mismatch; expected bool but got string', 'E1135: Using a String as a Bool', 1)
 
   CheckDefExecAndScriptFailure(['assert_equal(false, Record(1) && Record(4) && Record(0))'], 'E1023: Using a Number as a Bool: 4', 1)
 
-  var lines =<< trim END
+  lines =<< trim END
       if 3
           && true
       endif
@@ -976,6 +1007,12 @@ def Test_expr4_vim9script()
   END
   CheckDefAndScriptFailure(lines, 'E1004:', 1)
 
+  for op in ['==', '>', '>=', '<', '<=', '=~', '!~', 'is', 'isnot']
+    lines = ["echo 'aaa'", op .. "'bbb'", '# comment']
+    var msg = printf("E1004: White space required before and after '%s'", op)
+    CheckDefAndScriptFailure(lines, msg, 2)
+  endfor
+
   lines =<< trim END
     echo len('xxx') == 3
   END
@@ -1264,6 +1301,12 @@ def Test_expr5_vim9script()
       bwipe!
   END
   CheckDefAndScriptFailure(lines, "E1004: White space required before and after '/' at \"/pattern", 3)
+
+  for op in ['+', '-']
+    lines = ['var x = 1', op .. '2', '# comment']
+    var msg = printf("E1004: White space required before and after '%s' at \"%s2\"", op, op)
+    CheckDefAndScriptFailure(lines, msg, 2)
+  endfor
 enddef
 
 def Test_expr5_vim9script_channel()
@@ -1545,6 +1588,12 @@ func Test_expr6_fails()
   if has('float')
     call CheckDefAndScriptFailure2(["var x = 0.7[1]"], 'E1107:', 'E806:', 1)
   endif
+
+  for op in ['*', '/', '%']
+    let lines = ['var x = 1', op .. '2', '# comment']
+    let msg = printf("E1004: White space required before and after '%s' at \"%s2\"", op, op)
+    call CheckDefAndScriptFailure(lines, msg, 2)
+  endfor
 endfunc
 
 func Test_expr6_float_fails()
index 4cf2c3e303815081ea003fcdc6657295653fdee4..7c7e1136fedf6af3f3de51137297fce0fb993354 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2895,
 /**/
     2894,
 /**/
index cb91c3ccb9e07c33aa90f073f22b01e19f8c303b..995c1d7491ba28ee62c1d60d1e194a7e5d466c88 100644 (file)
@@ -5187,7 +5187,7 @@ compile_expr1(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
        if (!IS_WHITE_OR_NUL(**arg) || !IS_WHITE_OR_NUL(p[1 + op_falsy]))
        {
            semsg(_(e_white_space_required_before_and_after_str_at_str),
-                                                 op_falsy ? "??" : "?", *arg);
+                                                    op_falsy ? "??" : "?", p);
            return FAIL;
        }