0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

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)
This commit is contained in:
Bram Moolenaar
2021-02-17 14:52:14 +01:00
parent 3aca5a6fbc
commit e0890d678d
5 changed files with 33 additions and 10 deletions

View File

@@ -372,6 +372,19 @@ script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
return FAIL;
}
/*
* Return TRUE if "name" is a local variable, argument, script variable or
* imported.
*/
static int
variable_exists(char_u *name, size_t len, cctx_T *cctx)
{
return lookup_local(name, len, NULL, cctx) == OK
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK
|| script_var_exists(name, len, FALSE, cctx) == OK
|| find_imported(name, len, cctx) != NULL;
}
/*
* Check if "p[len]" is already defined, either in script "import_sid" or in
* 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)
|| *eap->cmd == '$'
|| *eap->cmd == '@'
|| ((len) > 2 && eap->cmd[1] == ':')
|| lookup_local(eap->cmd, len, NULL, cctx) == OK
|| arg_exists(eap->cmd, len, NULL, NULL, NULL, cctx) == OK
|| script_var_exists(eap->cmd, len, FALSE, cctx) == OK
|| find_imported(eap->cmd, len, cctx) != NULL)
|| variable_exists(eap->cmd, len, cctx))
{
*line = compile_assignment(eap->cmd, eap, CMD_SIZE, cctx);
if (*line == NULL || *line == eap->cmd)
@@ -8332,7 +8342,7 @@ compile_def_function(
}
}
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
: (int (*)(char_u *, size_t, void *, cctx_T *))lookup_local,
: (int (*)(char_u *, size_t, cctx_T *))variable_exists,
&cctx);
if (p == NULL)