]> granicus.if.org Git - vim/commitdiff
patch 8.2.2453: Vim9: a variable name with "->" in the next line doesn't work v8.2.2453
authorBram Moolenaar <Bram@vim.org>
Tue, 2 Feb 2021 20:33:52 +0000 (21:33 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 2 Feb 2021 20:33:52 +0000 (21:33 +0100)
Problem:    Vim9: a variable name with "->" in the next line doesn't work.
Solution:   Recognize a variable name by itself. (closes #7770)

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

index 8b9db68123bae4250db4a8d7899453667ce1f3ed..d31b56c8cea14a7e4ba319d3e5ce40e9a24ebd9e 100644 (file)
@@ -3424,6 +3424,16 @@ find_ex_command(
                return eap->cmd;
            }
        }
+
+       // If it is an ID it might be a variable with an operator on the next
+       // line, if the variable exists it can't be an Ex command.
+       if (p > eap->cmd && ends_excmd(*skipwhite(p))
+               && (lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK
+                   || (ASCII_ISALPHA(eap->cmd[0]) && eap->cmd[1] == ':')))
+       {
+           eap->cmdidx = CMD_eval;
+           return eap->cmd;
+       }
     }
 #endif
 
index 2f8fd71e95393abe4f2d84504b9463a7b461b5fd..ef0a5fe2e887ee79856d310e4396bc5e548721fb 100644 (file)
@@ -328,6 +328,29 @@ def Test_method_call_linebreak()
       assert_equal([1, 2, 3], res)
   END
   CheckScriptSuccess(lines)
+
+  lines =<< trim END
+      new
+      var name = [1, 2]
+      name
+          ->copy()
+          ->setline(1)
+      assert_equal(['1', '2'], getline(1, 2))
+      bwipe!
+  END
+  CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      new
+      g:shortlist
+          ->copy()
+          ->setline(1)
+      assert_equal(['1', '2'], getline(1, 2))
+      bwipe!
+  END
+  g:shortlist = [1, 2]
+  CheckDefAndScriptSuccess(lines)
+  unlet g:shortlist
 enddef
 
 def Test_method_call_whitespace()
index c5f21db2c847577645540efa3446bfc5df63c74a..679f3a57ebf8dd168544ff9f5eb2cdb27f9896da 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2453,
 /**/
     2452,
 /**/