]> granicus.if.org Git - vim/commitdiff
patch 8.2.1116: Vim9: parsing command checks for list twice v8.2.1116
authorBram Moolenaar <Bram@vim.org>
Thu, 2 Jul 2020 19:11:34 +0000 (21:11 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Jul 2020 19:11:34 +0000 (21:11 +0200)
Problem:    Vim9: parsing command checks for list twice.
Solution:   Adjust how a command is parsed.

src/ex_docmd.c
src/testdir/test_vim9_cmd.vim
src/version.c

index 0c55a57c5c292ab6f94ec57245f0b0a5518f0544..a5562cc28a8dde1689253ad4b06a8f9bba60c201 100644 (file)
@@ -3219,8 +3219,9 @@ find_ex_command(
      * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
      */
     p = eap->cmd;
-    if (lookup != NULL && (*p == '(' || *p == '[' || *p == '{'
-              || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL)))
+    if (lookup != NULL && (*p == '(' || *p == '{'
+              || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL)
+              || *p == '['))
     {
        int oplen;
        int heredoc;
@@ -3233,6 +3234,7 @@ find_ex_command(
        // "{..." is an dict expression.
        if (*p == '('
                || *p == '{'
+               || (*p == '[' && p > eap->cmd)
                || p[1] == ':'
                || (*p == '-' && p[1] == '>'))
        {
@@ -3240,6 +3242,18 @@ find_ex_command(
            return eap->cmd;
        }
 
+       // "[...]->Method()" is a list expression, but "[a, b] = Func()" is
+       // an assignment.
+       // If there is no line break inside the "[...]" then "p" is advanced to
+       // after the "]" by to_name_const_end(): check if a "=" follows.
+       // If "[...]" has a line break "p" still points at the "[" and it can't
+       // be an assignment.
+       if (*eap->cmd == '[' && (p == eap->cmd || *skipwhite(p) != '='))
+       {
+           eap->cmdidx = CMD_eval;
+           return eap->cmd;
+       }
+
        // Recognize an assignment if we recognize the variable name:
        // "g:var = expr"
        // "var = expr"  where "var" is a local var name.
@@ -3253,15 +3267,6 @@ find_ex_command(
                return eap->cmd;
            }
        }
-
-       // "[...]->Method()" is a list expression.  But "[a, b] = Func()" is
-       // an assignment.
-       if (*p == '[' && (eval_list(&p, NULL, NULL, FALSE) == FAIL
-                                                     || *skipwhite(p) != '='))
-       {
-           eap->cmdidx = CMD_eval;
-           return eap->cmd;
-       }
     }
 #endif
 
index ab91a164605be8ac7382d668586a34f7bdaffd8c..27d2b3a7cd9915396292ed1f7d4726ef6662b3d3 100644 (file)
@@ -190,7 +190,7 @@ def Test_for_linebreak()
   CheckScriptSuccess(lines)
 enddef
 
-def Test_method_cal_linebreak()
+def Test_method_call_linebreak()
   let lines =<< trim END
       vim9script
       let res = []
index fa8c63955c58fe010d7e004cbde4303310f0b733..54469ffc2b267c9edd4995d9eb542d1b9f6fd6a7 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1116,
 /**/
     1115,
 /**/