diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-16 17:05:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 17:05:59 +0800 |
commit | ead3a1bd7a3fbc266ae5bf724d74cd1c44286b50 (patch) | |
tree | 6a536fa16ec08b0d964a405377fdff3f3fa1f374 /src | |
parent | 848e64322a3246f351a44fc1955eecc5ea163c72 (diff) | |
download | rneovim-ead3a1bd7a3fbc266ae5bf724d74cd1c44286b50.tar.gz rneovim-ead3a1bd7a3fbc266ae5bf724d74cd1c44286b50.tar.bz2 rneovim-ead3a1bd7a3fbc266ae5bf724d74cd1c44286b50.zip |
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 (limited to 'src')
-rw-r--r-- | src/nvim/eval/userfunc.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index fe10d56d49..2ada0a0e59 100644 --- 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; } } |