Skip to content

Commit e0890d6

Browse files
committed
patch 8.2.2525: Vim9: only local variables checked for a name
Problem: Vim9: only local variables checked for a name. Solution: Also check arguments and script variables. (closes #7838)
1 parent 3aca5a6 commit e0890d6

5 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/ex_docmd.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3307,7 +3307,7 @@ skip_option_env_lead(char_u *start)
33073307
find_ex_command(
33083308
exarg_T *eap,
33093309
int *full UNUSED,
3310-
int (*lookup)(char_u *, size_t, void *, cctx_T *) UNUSED,
3310+
int (*lookup)(char_u *, size_t, cctx_T *) UNUSED,
33113311
cctx_T *cctx UNUSED)
33123312
{
33133313
int len;
@@ -3416,7 +3416,7 @@ find_ex_command(
34163416

34173417
// Recognize an assignment if we recognize the variable name:
34183418
// "g:var = expr"
3419-
// "var = expr" where "var" is a local var name.
3419+
// "var = expr" where "var" is a variable name.
34203420
if (*eap->cmd == '@')
34213421
p = eap->cmd + 2;
34223422
oplen = assignment_len(skipwhite(p), &heredoc);
@@ -3426,7 +3426,7 @@ find_ex_command(
34263426
|| *eap->cmd == '&'
34273427
|| *eap->cmd == '$'
34283428
|| *eap->cmd == '@'
3429-
|| lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK)
3429+
|| lookup(eap->cmd, p - eap->cmd, cctx) == OK)
34303430
{
34313431
eap->cmdidx = CMD_var;
34323432
return eap->cmd;
@@ -3445,7 +3445,7 @@ find_ex_command(
34453445
// If it is an ID it might be a variable with an operator on the next
34463446
// line, if the variable exists it can't be an Ex command.
34473447
if (p > eap->cmd && ends_excmd(*skipwhite(p))
3448-
&& (lookup(eap->cmd, p - eap->cmd, NULL, cctx) == OK
3448+
&& (lookup(eap->cmd, p - eap->cmd, cctx) == OK
34493449
|| (ASCII_ISALPHA(eap->cmd[0]) && eap->cmd[1] == ':')))
34503450
{
34513451
eap->cmdidx = CMD_eval;

src/proto/ex_docmd.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ void undo_cmdmod(cmdmod_T *cmod);
1313
int parse_cmd_address(exarg_T *eap, char **errormsg, int silent);
1414
int checkforcmd(char_u **pp, char *cmd, int len);
1515
char_u *skip_option_env_lead(char_u *start);
16-
char_u *find_ex_command(exarg_T *eap, int *full, int (*lookup)(char_u *, size_t, void *, cctx_T *), cctx_T *cctx);
16+
char_u *find_ex_command(exarg_T *eap, int *full, int (*lookup)(char_u *, size_t, cctx_T *), cctx_T *cctx);
1717
int modifier_len(char_u *cmd);
1818
int cmd_exists(char_u *name);
19+
void f_fullcommand(typval_T *argvars, typval_T *rettv);
1920
cmdidx_T excmd_get_cmdidx(char_u *cmd, int len);
2021
long excmd_get_argt(cmdidx_T idx);
2122
char_u *skip_range(char_u *cmd, int skip_star, int *ctx);

src/testdir/test_vim9_cmd.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,11 @@ def Test_for_linebreak()
323323
CheckScriptSuccess(lines)
324324
enddef
325325

326+
def MethodAfterLinebreak(arg: string)
327+
arg
328+
->setline(1)
329+
enddef
330+
326331
def Test_method_call_linebreak()
327332
var lines =<< trim END
328333
vim9script
@@ -361,6 +366,11 @@ def Test_method_call_linebreak()
361366
g:shortlist = [1, 2]
362367
CheckDefAndScriptSuccess(lines)
363368
unlet g:shortlist
369+
370+
new
371+
MethodAfterLinebreak('foobar')
372+
assert_equal('foobar', getline(1))
373+
bwipe!
364374
enddef
365375

366376
def Test_method_call_whitespace()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2525,
753755
/**/
754756
2524,
755757
/**/

src/vim9compile.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,19 @@ script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
372372
return FAIL;
373373
}
374374

375+
/*
376+
* Return TRUE if "name" is a local variable, argument, script variable or
377+
* imported.
378+
*/
379+
static int
380+
variable_exists(char_u *name, size_t len, cctx_T *cctx)
381+
{
382+
return lookup_local(name, len, NULL, cctx) == OK
383+
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK
384+
|| script_var_exists(name, len, FALSE, cctx) == OK
385+
|| find_imported(name, len, cctx) != NULL;
386+
}
387+
375388
/*
376389
* Check if "p[len]" is already defined, either in script "import_sid" or in
377390
* compilation context "cctx". "cctx" is NULL at the script level.
@@ -6444,10 +6457,7 @@ may_compile_assignment(exarg_T *eap, char_u **line, cctx_T *cctx)
64446457
|| *eap->cmd == '$'
64456458
|| *eap->cmd == '@'
64466459
|| ((len) > 2 && eap->cmd[1] == ':')
6447-
|| lookup_local(eap->cmd, len, NULL, cctx) == OK
6448-
|| arg_exists(eap->cmd, len, NULL, NULL, NULL, cctx) == OK
6449-
|| script_var_exists(eap->cmd, len, FALSE, cctx) == OK
6450-
|| find_imported(eap->cmd, len, cctx) != NULL)
6460+
|| variable_exists(eap->cmd, len, cctx))
64516461
{
64526462
*line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
64536463
if (*line == NULL || *line == eap->cmd)
@@ -8332,7 +8342,7 @@ compile_def_function(
83328342
}
83338343
}
83348344
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
8335-
: (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
8345+
: (int (*)(char_u *, size_t, cctx_T *))variable_exists,
83368346
&cctx);
83378347

83388348
if (p == NULL)

0 commit comments

Comments
 (0)