vim-patch:8.2.3782: Vim9: no error if a function shadows a script variable (#27881)

Problem:    Vim9: no error if a function shadows a script variable.
Solution:   Check the function doesn't shadow a variable. (closes vim/vim#9310)

052ff291d7

Omit EVAL_VAR_NO_FUNC: Vim9 script only.

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
zeertzjq 2024-03-16 17:05:59 +08:00 committed by GitHub
parent 848e64322a
commit ead3a1bd7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2294,17 +2294,27 @@ void ex_function(exarg_T *eap)
arg = fudi.fd_newkey;
}
if (arg != NULL && (fudi.fd_di == NULL || !tv_is_func(fudi.fd_di->di_tv))) {
int j = ((uint8_t)(*arg) == K_SPECIAL) ? 3 : 0;
while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j]) : eval_isnamec(arg[j]))) {
j++;
char *name_base = arg;
if ((uint8_t)(*arg) == K_SPECIAL) {
name_base = vim_strchr(arg, '_');
if (name_base == NULL) {
name_base = arg + 3;
} else {
name_base++;
}
if (arg[j] != NUL) {
}
int i;
for (i = 0; name_base[i] != NUL && (i == 0
? eval_isnamec1(name_base[i])
: eval_isnamec(name_base[i])); i++) {}
if (name_base[i] != NUL) {
emsg_funcname(e_invarg2, arg);
}
}
// Disallow using the g: dict.
if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) {
emsg(_("E862: Cannot use g: here"));
goto ret_free;
}
}