Skip to content

Commit

Permalink
patch 8.2.1116: Vim9: parsing command checks for list twice
Browse files Browse the repository at this point in the history
Problem:    Vim9: parsing command checks for list twice.
Solution:   Adjust how a command is parsed.
  • Loading branch information
brammool committed Jul 2, 2020
1 parent c19fd91 commit d2ef6b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
27 changes: 16 additions & 11 deletions src/ex_docmd.c
Expand Up @@ -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;
Expand All @@ -3233,13 +3234,26 @@ find_ex_command(
// "{..." is an dict expression.
if (*p == '('
|| *p == '{'
|| (*p == '[' && p > eap->cmd)
|| p[1] == ':'
|| (*p == '-' && p[1] == '>'))
{
eap->cmdidx = CMD_eval;
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.
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/testdir/test_vim9_cmd.vim
Expand Up @@ -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 = []
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -754,6 +754,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1116,
/**/
1115,
/**/
Expand Down

0 comments on commit d2ef6b3

Please sign in to comment.