0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.4260: Vim9: can still use a global function without g:

Problem:    Vim9: can still use a global function without g: at the script
            level.
Solution:   Also check for g: at the script level. (issue #9637)
This commit is contained in:
Bram Moolenaar
2022-01-30 15:28:30 +00:00
parent 06011e1a55
commit 848faddb87
16 changed files with 102 additions and 54 deletions

View File

@@ -2779,17 +2779,20 @@ eval_variable(
}
else if (in_vim9script() && (flags & EVAL_VAR_NO_FUNC) == 0)
{
int has_g_prefix = STRNCMP(name, "g:", 2) == 0;
ufunc_T *ufunc = find_func(name, FALSE);
// In Vim9 script we can get a function reference by using the
// function name.
if (ufunc != NULL)
// function name. For a global non-autoload function "g:" is
// required.
if (ufunc != NULL && (has_g_prefix
|| !func_requires_g_prefix(ufunc)))
{
found = TRUE;
if (rettv != NULL)
{
rettv->v_type = VAR_FUNC;
if (STRNCMP(name, "g:", 2) == 0)
if (has_g_prefix)
// Keep the "g:", otherwise script-local may be
// assumed.
rettv->vval.v_string = vim_strsave(name);