patch 8.2.0298: Vim9 script: cannot start command with a string constant
Problem: Vim9 script: cannot start command with a string constant.
Solution: Recognize expression starting with '('.
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 511e8c5..70c0da2 100644
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -3146,8 +3146,9 @@
* 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 @@
// "varname[]" is an expression.
// "g:varname" is an expression.
// "varname->expr" is an expression.
+ // "(..." is an expression.
if (*p == '('
|| *p == '['
|| p[1] == ':'
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 107ee02..5dbc9f9 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -370,6 +370,11 @@
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
diff --git a/src/version.c b/src/version.c
index aa9ff36..d889ce7 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 298,
+/**/
297,
/**/
296,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index aeb950c..6408b67 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4821,22 +4821,11 @@
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)
{