]> granicus.if.org Git - vim/commitdiff
patch 8.2.0298: Vim9 script: cannot start command with a string constant v8.2.0298
authorBram Moolenaar <Bram@vim.org>
Sat, 22 Feb 2020 17:36:32 +0000 (18:36 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 Feb 2020 17:36:32 +0000 (18:36 +0100)
Problem:    Vim9 script: cannot start command with a string constant.
Solution:   Recognize expression starting with '('.

runtime/doc/vim9.txt
src/ex_docmd.c
src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index c79ae62de103ab70e8c3572a2829f345e936c875..05c1c8e3deb30436a5b7e2378afb159c5f36ed1d 100644 (file)
@@ -131,21 +131,23 @@ Functions can be called without `:call`: >
 Using `:call` is still possible, but this is discouraged.
 
 A method call without `eval` is possible, so long as the start is an
-identifier or can't be an Ex command.  It does not work for string constants: >
+identifier or can't be an Ex command.  It does NOT work for string constants: >
        myList->add(123)                " works
        g:myList->add(123)              " works
        [1, 2, 3]->Process()            " works
        #{a: 1, b: 2}->Process()        " works
        {'a': 1, 'b': 2}->Process()     " works
        "foobar"->Process()             " does NOT work
-       eval "foobar"->Process()        " works
+       ("foobar")->Process()           " works
+       'foobar'->Process()             " does NOT work
+       ('foobar')->Process()           " works
 
 In case there is ambiguity between a function name and an Ex command, use ":"
 to make clear you want to use the Ex command.  For example, there is both the
 `:substitute` command and the `substitute()` function.  When the line starts
 with `substitute(` this will use the function, prepend a colon to use the
 command instead: >
-       :substitute(pattern(replacement(
+       :substitute(pattern (replacement (
 
 
 No curly braces expansion ~
index 511e8c5dea44c7ee5f19627b6d418c48f0d790f1..70c0da2f033ac6d493a242c55cf0f57f82608fd6 100644 (file)
@@ -3146,8 +3146,9 @@ find_ex_command(
      * Recognize a Vim9 script function/method call and assignment:
      * "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
      */
-    if (lookup != NULL && (p = to_name_const_end(eap->cmd)) > eap->cmd
-                                                                 && *p != NUL)
+    p = eap->cmd;
+    if (lookup != NULL && (*p == '('
+              || ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL)))
     {
        int oplen;
        int heredoc;
@@ -3156,6 +3157,7 @@ find_ex_command(
        // "varname[]" is an expression.
        // "g:varname" is an expression.
        // "varname->expr" is an expression.
+       // "(..." is an expression.
        if (*p == '('
                || *p == '['
                || p[1] == ':'
index 107ee02450637116204d289e09b92e0a85af4910..5dbc9f9ea7772d8ea016caf51828741368928b65 100644 (file)
@@ -370,6 +370,11 @@ def Test_vim9script_call()
     assert_equal(#{a: 1, b: 2}, dictvar)
     #{a: 3, b: 4}->DictFunc()
     assert_equal(#{a: 3, b: 4}, dictvar)
+
+    ('text')->MyFunc()
+    assert_equal('text', var)
+    ("some")->MyFunc()
+    assert_equal('some', var)
   END
   writefile(lines, 'Xcall.vim')
   source Xcall.vim
index aa9ff36fafa399e6f80bbf8b76c44df063ea18c1..d889ce7e8af5a81e206273c6ee808a473650a8fa 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    298,
 /**/
     297,
 /**/
index aeb950ca6a939182f98624217ae20acaa6ed2dae..6408b67bf75ed6112f27f974591b09b2320d1777 100644 (file)
@@ -4821,22 +4821,11 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
            p = (*ea.cmd == '&' || *ea.cmd == '$' || *ea.cmd == '@')
                                                         ? ea.cmd + 1 : ea.cmd;
            p = to_name_end(p);
-           if (p > ea.cmd && *p != NUL)
+           if ((p > ea.cmd && *p != NUL) || *p == '(')
            {
                int oplen;
                int heredoc;
 
-               // "funcname(" is always a function call.
-               // "varname[]" is an expression.
-               // "varname->expr" is an expression.
-               if (*p == '('
-                       || *p == '['
-                       || ((p - ea.cmd) > 2 && ea.cmd[1] == ':')
-                       || (*p == '-' && p[1] == '>'))
-               {
-                   // TODO
-               }
-
                oplen = assignment_len(skipwhite(p), &heredoc);
                if (oplen > 0)
                {