]> granicus.if.org Git - vim/commitdiff
patch 8.2.1326: Vim9: skipping over white space after list v8.2.1326
authorBram Moolenaar <Bram@vim.org>
Thu, 30 Jul 2020 18:08:50 +0000 (20:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 30 Jul 2020 18:08:50 +0000 (20:08 +0200)
Problem:    Vim9: skipping over white space after list.
Solution:   Do not skip white space, a following [] would be misinterpreted.
            (closes #6552)  Fix a few side effects.

src/dict.c
src/eval.c
src/list.c
src/testdir/test_functions.vim
src/testdir/test_gn.vim
src/testdir/test_popupwin.vim
src/testdir/test_tabpage.vim
src/testdir/test_textobjects.vim
src/testdir/test_textprop.vim
src/userfunc.c
src/version.c

index eedaf42686ff2215477c26e18f4c249bb516c86c..019227f1054efb8a4aa5f306dd2118c38250c2be 100644 (file)
@@ -838,6 +838,10 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
                : eval1(arg, &tvkey, evalarg)) == FAIL) // recursive!
            goto failret;
 
+       // The colon should come right after the key, but this wasn't checked
+       // previously, so only require it in Vim9 script.
+       if (!vim9script)
+           *arg = skipwhite(*arg);
        if (**arg != ':')
        {
            if (evaluate)
index 451bb16b7c58d649c1d31184706eb12ddcb38be2..119b7cc189ac4c4cb68d0782ab2c0365d558fdad 100644 (file)
@@ -1913,27 +1913,28 @@ eval_func(
     char_u *
 eval_next_non_blank(char_u *arg, evalarg_T *evalarg, int *getnext)
 {
+    char_u *p = skipwhite(arg);
+
     *getnext = FALSE;
     if (in_vim9script()
            && evalarg != NULL
            && (evalarg->eval_cookie != NULL || evalarg->eval_cctx != NULL)
-           && (*arg == NUL || (VIM_ISWHITE(arg[-1])
-                                                 && vim9_comment_start(arg))))
+           && (*p == NUL || (VIM_ISWHITE(p[-1]) && vim9_comment_start(p))))
     {
-       char_u *p;
+       char_u *next;
 
        if (evalarg->eval_cookie != NULL)
-           p = getline_peek(evalarg->eval_getline, evalarg->eval_cookie);
+           next = getline_peek(evalarg->eval_getline, evalarg->eval_cookie);
        else
-           p = peek_next_line_from_context(evalarg->eval_cctx);
+           next = peek_next_line_from_context(evalarg->eval_cctx);
 
-       if (p != NULL)
+       if (next != NULL)
        {
            *getnext = TRUE;
-           return skipwhite(p);
+           return skipwhite(next);
        }
     }
-    return arg;
+    return p;
 }
 
 /*
@@ -2039,6 +2040,7 @@ eval0(
 
     p = skipwhite(arg);
     ret = eval1(&p, rettv, evalarg);
+    p = skipwhite(p);
 
     if (ret == FAIL || !ends_excmd2(arg, p))
     {
@@ -2107,6 +2109,8 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
 
        if (getnext)
            *arg = eval_next_line(evalarg_used);
+       else
+           *arg = p;
 
        result = FALSE;
        if (evaluate)
@@ -2142,6 +2146,8 @@ eval1(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        }
        if (getnext)
            *arg = eval_next_line(evalarg_used);
+       else
+           *arg = p;
 
        /*
         * Get the third variable.  Recursive!
@@ -2234,6 +2240,8 @@ eval2(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        {
            if (getnext)
                *arg = eval_next_line(evalarg_used);
+           else
+               *arg = p;
 
            /*
             * Get the second variable.
@@ -2349,6 +2357,8 @@ eval3(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
        {
            if (getnext)
                *arg = eval_next_line(evalarg_used);
+           else
+               *arg = p;
 
            /*
             * Get the second variable.
@@ -2575,6 +2585,8 @@ eval5(char_u **arg, typval_T *rettv, evalarg_T *evalarg)
 
        if (getnext)
            *arg = eval_next_line(evalarg);
+       else
+           *arg = p;
        evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
        if ((op != '+' || (rettv->v_type != VAR_LIST
                                                 && rettv->v_type != VAR_BLOB))
@@ -2756,6 +2768,7 @@ eval6(
        int         evaluate;
        int         getnext;
        typval_T    var2;
+       char_u      *p;
        int         op;
        varnumber_T n1, n2;
 #ifdef FEAT_FLOAT
@@ -2763,12 +2776,15 @@ eval6(
 #endif
        int         error;
 
-       op = *eval_next_non_blank(*arg, evalarg, &getnext);
+       p = eval_next_non_blank(*arg, evalarg, &getnext);
+       op = *p;
        if (op != '*' && op != '/' && op != '%')
            break;
 
        if (getnext)
            *arg = eval_next_line(evalarg);
+       else
+           *arg = p;
 
 #ifdef FEAT_FLOAT
        f1 = 0;
@@ -3115,8 +3131,6 @@ eval7(
        vim_free(alias);
     }
 
-    *arg = skipwhite(*arg);
-
     // Handle following '[', '(' and '.' for expr[expr], expr.name,
     // expr(expr), expr->name(expr)
     if (ret == OK)
@@ -5152,7 +5166,7 @@ handle_subscript(
        p = eval_next_non_blank(*arg, evalarg, &getnext);
        if (getnext
            && ((rettv->v_type == VAR_DICT && *p == '.' && eval_isdictc(p[1]))
-               || (*p == '-' && p[1] == '>'
+               || (p[0] == '-' && p[1] == '>'
                                     && (p[2] == '{' || ASCII_ISALPHA(p[2])))))
        {
            *arg = eval_next_line(evalarg);
@@ -5178,8 +5192,9 @@ handle_subscript(
            dict_unref(selfdict);
            selfdict = NULL;
        }
-       else if (**arg == '-' && (*arg)[1] == '>')
+       else if (p[0] == '-' && p[1] == '>')
        {
+           *arg = p;
            if (ret == OK)
            {
                if ((*arg)[2] == '{')
index 9a334ae45bce726a34f0e6789e3ad5f39cc96051..5c2f60ef79981a45c2e9b7743667e513d509f3e2 100644 (file)
@@ -1199,7 +1199,7 @@ eval_list(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int do_error)
        had_comma = **arg == ',';
        if (had_comma)
        {
-           if (vim9script && (*arg)[1] != NUL && !VIM_ISWHITE((*arg)[1]))
+           if (vim9script && !IS_WHITE_OR_NUL((*arg)[1]))
            {
                semsg(_(e_white_after), ",");
                goto failret;
@@ -1231,7 +1231,7 @@ failret:
        return FAIL;
     }
 
-    *arg = skipwhite(*arg + 1);
+    *arg += 1;
     if (evaluate)
        rettv_list_set(rettv, l);
 
index 9aa830b2f5bea485c5a245fd9ad084b5ec15ca98..7aaeeb7ae3895405460c07468f70e78e2a55c102 100644 (file)
@@ -1355,7 +1355,7 @@ func Test_input_func()
   func! Tcomplete(arglead, cmdline, pos)
     return "item1\nitem2\nitem3"
   endfunc
-  call feedkeys(":let c = input('Q? ', '' , 'custom,Tcomplete')\<CR>"
+  call feedkeys(":let c = input('Q? ', '', 'custom,Tcomplete')\<CR>"
         \ .. "\<C-A>\<CR>", 'xt')
   delfunc Tcomplete
   call assert_equal('item1 item2 item3', c)
index c72da925a3fde4e37dd2f51051036ff3ab9608db..b90aa5f1d617533850753d99f6f847141c7390d5 100644 (file)
@@ -120,7 +120,7 @@ func Test_gn_command()
   sil! %d_
 
   " search using the \zs atom
-  call setline(1, [' nnoremap', '' , 'nnoremap'])
+  call setline(1, [' nnoremap', '', 'nnoremap'])
   set wrapscan&vim
   let @/ = '\_s\zsnnoremap'
   $
index 00b956a9e0dccb7dd446495b9c92dcbb86686d75..30dfc6693acdc15fa457b40be7412922af7482d3 100644 (file)
@@ -588,7 +588,7 @@ func Test_popup_drag_termwin()
        call setline(1, range(100))
        for nr in range(7)
          call setline(nr * 12 + 1, "fold {{{")
-         call setline(nr * 12 + 11 , "end }}}")
+         call setline(nr * 12 + 11, "end }}}")
        endfor
        %foldclose
        set shell=/bin/sh noruler
index 33fdab47800379db7e81466f2d844fc65903aaa2..bbcafa8eb6fd343cc7fd0caed72e4dedeb6f42d7 100644 (file)
@@ -350,7 +350,7 @@ function Test_tabpage_with_tabprevious()
     call Check_tab_count(6, cmd . ' 3', 3)
     call Check_tab_count(6, cmd . ' 8', 4)
     for n in range(2)
-      for c in ['0', '.+3', '+', '+2' , '-', '-2' , '$', '+99', '-99']
+      for c in ['0', '.+3', '+', '+2', '-', '-2', '$', '+99', '-99']
         if n == 0 " pre count
           let entire_cmd = c . cmd
           let err_code = 'E16:'
index 6eb6fbbf3ff8cbad46c3fe9bcc3727a0e5f156a2..54de3f89dce51cc28de957e30c47c6d3cf0ed2ab 100644 (file)
@@ -201,28 +201,28 @@ func Test_match()
   call assert_equal("c", matchstr("abcd", ".", 2, 0))
   call assert_equal("a", matchstr("abcd", ".", 0, -1))
   call assert_equal(-1, match("abcd", ".", 0, 5))
-  call assert_equal(0 , match("abcd", ".", 0, -1))
-  call assert_equal(0 , match('abc', '.', 0, 1))
-  call assert_equal(1 , match('abc', '.', 0, 2))
-  call assert_equal(2 , match('abc', '.', 0, 3))
+  call assert_equal(0, match("abcd", ".", 0, -1))
+  call assert_equal(0, match('abc', '.', 0, 1))
+  call assert_equal(1, match('abc', '.', 0, 2))
+  call assert_equal(2, match('abc', '.', 0, 3))
   call assert_equal(-1, match('abc', '.', 0, 4))
-  call assert_equal(1 , match('abc', '.', 1, 1))
-  call assert_equal(2 , match('abc', '.', 2, 1))
+  call assert_equal(1, match('abc', '.', 1, 1))
+  call assert_equal(2, match('abc', '.', 2, 1))
   call assert_equal(-1, match('abc', '.', 3, 1))
-  call assert_equal(3 , match('abc', '$', 0, 1))
+  call assert_equal(3, match('abc', '$', 0, 1))
   call assert_equal(-1, match('abc', '$', 0, 2))
-  call assert_equal(3 , match('abc', '$', 1, 1))
-  call assert_equal(3 , match('abc', '$', 2, 1))
-  call assert_equal(3 , match('abc', '$', 3, 1))
+  call assert_equal(3, match('abc', '$', 1, 1))
+  call assert_equal(3, match('abc', '$', 2, 1))
+  call assert_equal(3, match('abc', '$', 3, 1))
   call assert_equal(-1, match('abc', '$', 4, 1))
-  call assert_equal(0 , match('abc', '\zs', 0, 1))
-  call assert_equal(1 , match('abc', '\zs', 0, 2))
-  call assert_equal(2 , match('abc', '\zs', 0, 3))
-  call assert_equal(3 , match('abc', '\zs', 0, 4))
+  call assert_equal(0, match('abc', '\zs', 0, 1))
+  call assert_equal(1, match('abc', '\zs', 0, 2))
+  call assert_equal(2, match('abc', '\zs', 0, 3))
+  call assert_equal(3, match('abc', '\zs', 0, 4))
   call assert_equal(-1, match('abc', '\zs', 0, 5))
-  call assert_equal(1 , match('abc', '\zs', 1, 1))
-  call assert_equal(2 , match('abc', '\zs', 2, 1))
-  call assert_equal(3 , match('abc', '\zs', 3, 1))
+  call assert_equal(1, match('abc', '\zs', 1, 1))
+  call assert_equal(2, match('abc', '\zs', 2, 1))
+  call assert_equal(3, match('abc', '\zs', 3, 1))
   call assert_equal(-1, match('abc', '\zs', 4, 1))
 endfunc
 
index d5f67b49bea628303fce362b5b4f56b293d4022b..9db5275d5219d66db37e6d44d32523445a42d552 100644 (file)
@@ -1219,7 +1219,7 @@ func Test_prop_func_invalid_args()
   call assert_fails('call prop_find({}, "x")', 'E474:')
   call assert_fails('call prop_find({"lnum" : -2})', 'E16:')
   call assert_fails('call prop_list(1, [])', 'E715:')
-  call assert_fails('call prop_list(-1 , {})', 'E16:')
+  call assert_fails('call prop_list(-1, {})', 'E16:')
   call assert_fails('call prop_remove([])', 'E474:')
   call assert_fails('call prop_remove({}, -2)', 'E16:')
   call assert_fails('call prop_remove({})', 'E968:')
index 343c9cd2e1dd22d659cc222d12f0cb02963e427a..de0cdb7ea51c9842d15cadcca5d3ea2026c1c03c 100644 (file)
@@ -642,6 +642,10 @@ get_func_tv(
            break;
        }
        ++argcount;
+       // The comma should come right after the argument, but this wasn't
+       // checked previously, thus only enforce it in Vim9 script.
+       if (!in_vim9script())
+           argp = skipwhite(argp);
        if (*argp != ',')
            break;
     }
index 02fa087806ef34e0e60e52d68e3edff213c6c05c..c37fbe46fc281a435d1b5106996486d65ba8563f 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1326,
 /**/
     1325,
 /**/