mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1218: Vim9: cannot use 'text'->func()
Problem: Vim9: cannot use 'text'->func(). Solution: Recognize string at start of command.
This commit is contained in:
@@ -1700,6 +1700,8 @@ do_one_cmd(
|
|||||||
char_u *cmd;
|
char_u *cmd;
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
int starts_with_colon;
|
int starts_with_colon;
|
||||||
|
int starts_with_quote;
|
||||||
|
int vim9script = in_vim9script();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CLEAR_FIELD(ea);
|
CLEAR_FIELD(ea);
|
||||||
@@ -1760,12 +1762,16 @@ do_one_cmd(
|
|||||||
* We need the command to know what kind of range it uses.
|
* We need the command to know what kind of range it uses.
|
||||||
*/
|
*/
|
||||||
cmd = ea.cmd;
|
cmd = ea.cmd;
|
||||||
ea.cmd = skip_range(ea.cmd, NULL);
|
#ifdef FEAT_EVAL
|
||||||
|
starts_with_quote = vim9script && *ea.cmd == '\'';
|
||||||
|
if (!starts_with_quote)
|
||||||
|
#endif
|
||||||
|
ea.cmd = skip_range(ea.cmd, NULL);
|
||||||
if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL)
|
if (*ea.cmd == '*' && vim_strchr(p_cpo, CPO_STAR) == NULL)
|
||||||
ea.cmd = skipwhite(ea.cmd + 1);
|
ea.cmd = skipwhite(ea.cmd + 1);
|
||||||
|
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
if (in_vim9script() && !starts_with_colon)
|
if (vim9script && !starts_with_colon)
|
||||||
{
|
{
|
||||||
if (ea.cmd > cmd)
|
if (ea.cmd > cmd)
|
||||||
{
|
{
|
||||||
@@ -1859,8 +1865,11 @@ do_one_cmd(
|
|||||||
}
|
}
|
||||||
|
|
||||||
ea.cmd = cmd;
|
ea.cmd = cmd;
|
||||||
if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)
|
#ifdef FEAT_EVAL
|
||||||
goto doend;
|
if (!starts_with_quote)
|
||||||
|
#endif
|
||||||
|
if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)
|
||||||
|
goto doend;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 5. Parse the command.
|
* 5. Parse the command.
|
||||||
@@ -1880,7 +1889,7 @@ do_one_cmd(
|
|||||||
if (*ea.cmd == NUL || *ea.cmd == '"'
|
if (*ea.cmd == NUL || *ea.cmd == '"'
|
||||||
#ifdef FEAT_EVAL
|
#ifdef FEAT_EVAL
|
||||||
|| (*ea.cmd == '#' && ea.cmd[1] != '{'
|
|| (*ea.cmd == '#' && ea.cmd[1] != '{'
|
||||||
&& !starts_with_colon && in_vim9script())
|
&& !starts_with_colon && vim9script)
|
||||||
#endif
|
#endif
|
||||||
|| (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL)
|
|| (ea.nextcmd = check_nextcmd(ea.cmd)) != NULL)
|
||||||
{
|
{
|
||||||
@@ -3223,26 +3232,34 @@ find_ex_command(
|
|||||||
* "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
|
* "lvar = value", "lvar(arg)", "[1, 2 3]->Func()"
|
||||||
*/
|
*/
|
||||||
p = eap->cmd;
|
p = eap->cmd;
|
||||||
if (lookup != NULL && (*p == '(' || *p == '{'
|
if (lookup != NULL && (vim_strchr((char_u *)"{('[", *p) != NULL
|
||||||
|| ((p = to_name_const_end(eap->cmd)) > eap->cmd && *p != NUL)
|
|| ((p = to_name_const_end(eap->cmd)) > eap->cmd
|
||||||
|| *p == '['))
|
&& *p != NUL)))
|
||||||
{
|
{
|
||||||
int oplen;
|
int oplen;
|
||||||
int heredoc;
|
int heredoc;
|
||||||
|
|
||||||
// "funcname(" is always a function call.
|
if (
|
||||||
// "varname[]" is an expression.
|
// "(..." is an expression.
|
||||||
// "g:varname" is an expression.
|
// "funcname(" is always a function call.
|
||||||
// "varname->expr" is an expression.
|
*p == '('
|
||||||
// "varname.expr" is an expression.
|
|| (p == eap->cmd
|
||||||
// "(..." is an expression.
|
? (
|
||||||
// "{..." is an dict expression.
|
// "{..." is an dict expression.
|
||||||
if (*p == '('
|
*eap->cmd == '{'
|
||||||
|| *p == '{'
|
// "'string'->func()" is an expression.
|
||||||
|| (*p == '[' && p > eap->cmd)
|
|| *eap->cmd == '\''
|
||||||
|| p[1] == ':'
|
// "g:varname" is an expression.
|
||||||
|| (*p == '-' && p[1] == '>')
|
|| eap->cmd[1] == ':'
|
||||||
|| (*p == '.' && ASCII_ISALPHA(p[1])))
|
)
|
||||||
|
: (
|
||||||
|
// "varname[]" is an expression.
|
||||||
|
*p == '['
|
||||||
|
// "varname->func()" is an expression.
|
||||||
|
|| (*p == '-' && p[1] == '>')
|
||||||
|
// "varname.expr" is an expression.
|
||||||
|
|| (*p == '.' && ASCII_ISALPHA(p[1]))
|
||||||
|
)))
|
||||||
{
|
{
|
||||||
eap->cmdidx = CMD_eval;
|
eap->cmdidx = CMD_eval;
|
||||||
return eap->cmd;
|
return eap->cmd;
|
||||||
|
@@ -355,6 +355,15 @@ def Test_vim9script_call()
|
|||||||
("some")->MyFunc()
|
("some")->MyFunc()
|
||||||
assert_equal('some', var)
|
assert_equal('some', var)
|
||||||
|
|
||||||
|
'asdfasdf'->MyFunc()
|
||||||
|
assert_equal('asdfasdf', var)
|
||||||
|
|
||||||
|
def UseString()
|
||||||
|
'xyork'->MyFunc()
|
||||||
|
enddef
|
||||||
|
UseString()
|
||||||
|
assert_equal('xyork', var)
|
||||||
|
|
||||||
MyFunc(
|
MyFunc(
|
||||||
'continued'
|
'continued'
|
||||||
)
|
)
|
||||||
|
@@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1218,
|
||||||
/**/
|
/**/
|
||||||
1217,
|
1217,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -7048,13 +7048,17 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* COMMAND after range
|
* COMMAND after range
|
||||||
|
* 'text'->func() should not be confused with 'a mark
|
||||||
*/
|
*/
|
||||||
cmd = ea.cmd;
|
cmd = ea.cmd;
|
||||||
ea.cmd = skip_range(ea.cmd, NULL);
|
if (*cmd != '\'')
|
||||||
if (ea.cmd > cmd && !starts_with_colon)
|
|
||||||
{
|
{
|
||||||
emsg(_(e_colon_required));
|
ea.cmd = skip_range(ea.cmd, NULL);
|
||||||
goto erret;
|
if (ea.cmd > cmd && !starts_with_colon)
|
||||||
|
{
|
||||||
|
emsg(_(e_colon_required));
|
||||||
|
goto erret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
|
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
|
||||||
: (void *(*)(char_u *, size_t, cctx_T *))lookup_local,
|
: (void *(*)(char_u *, size_t, cctx_T *))lookup_local,
|
||||||
|
Reference in New Issue
Block a user