diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-01-30 15:28:30 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-01-30 15:28:30 +0000 |
commit | 848faddb870f3ba4d84fcacd1cccb5cdbbfd9c41 (patch) | |
tree | 2215ac87eeddd465bb8339ca6654a4edde1efd52 /src/vim9expr.c | |
parent | 06011e1a55f32e47fe0af4bd449be6f0e3ff0814 (diff) | |
download | vim-git-848faddb870f3ba4d84fcacd1cccb5cdbbfd9c41.tar.gz |
patch 8.2.4260: Vim9: can still use a global function without g:v8.2.4260
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)
Diffstat (limited to 'src/vim9expr.c')
-rw-r--r-- | src/vim9expr.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/vim9expr.c b/src/vim9expr.c index 2727c5c70..6affac22e 100644 --- a/src/vim9expr.c +++ b/src/vim9expr.c @@ -349,11 +349,12 @@ compile_load_scriptvar( } static int -generate_funcref(cctx_T *cctx, char_u *name) +generate_funcref(cctx_T *cctx, char_u *name, int has_g_prefix) { ufunc_T *ufunc = find_func(name, FALSE); - if (ufunc == NULL) + // Reject a global non-autoload function found without the "g:" prefix. + if (ufunc == NULL || (!has_g_prefix && func_requires_g_prefix(ufunc))) return FAIL; // Need to compile any default values to get the argument types. @@ -420,7 +421,7 @@ compile_load( break; case 's': if (is_expr && ASCII_ISUPPER(*name) && find_func(name, FALSE) != NULL) - res = generate_funcref(cctx, name); + res = generate_funcref(cctx, name, FALSE); else res = compile_load_scriptvar(cctx, name, NULL, &end, error); @@ -429,7 +430,7 @@ compile_load( { if (is_expr && ASCII_ISUPPER(*name) && find_func(name, FALSE) != NULL) - res = generate_funcref(cctx, name); + res = generate_funcref(cctx, name, TRUE); else isn_type = ISN_LOADG; } @@ -505,7 +506,7 @@ compile_load( // uppercase letter it can be a user defined function. // generate_funcref() will fail if the function can't be found. if (res == FAIL && is_expr && ASCII_ISUPPER(*name)) - res = generate_funcref(cctx, name); + res = generate_funcref(cctx, name, FALSE); } } if (gen_load) @@ -812,7 +813,7 @@ compile_call( // If the name is a variable, load it and use PCALL. // Not for g:Func(), we don't know if it is a variable or not. - // Not for eome#Func(), it will be loaded later. + // Not for some#Func(), it will be loaded later. p = namebuf; if (!has_g_namespace && !is_autoload && compile_load(&p, namebuf + varlen, cctx, FALSE, FALSE) == OK) |