commit ead3a1bd7a3fbc266ae5bf724d74cd1c44286b50
parent 848e64322a3246f351a44fc1955eecc5ea163c72
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sat, 16 Mar 2024 17:05:59 +0800
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)
https://github.com/vim/vim/commit/052ff291d72bc9c176f9562f021d7e8e030e74c0
Omit EVAL_VAR_NO_FUNC: Vim9 script only.
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat:
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
@@ -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;
}
}