diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-02-22 19:39:13 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-02-22 19:39:13 +0000 |
commit | fe73255c92b6cb54851f82fa32458340b736298d (patch) | |
tree | a2b7a346b7178ec3bca0b2ef1fd163fb6b0682c2 /src/vim9execute.c | |
parent | 29a9e6971849b4a9eabf14fee1130d51cecfbaa7 (diff) | |
download | vim-git-fe73255c92b6cb54851f82fa32458340b736298d.tar.gz |
patch 8.2.4446: Vim9: cannot refer to a global function like a local onev8.2.4446
Problem: Vim9: cannot refer to a global function like a local one.
Solution: When g:name is not a variable but a function, use a function
reference. (closes #9826)
Diffstat (limited to 'src/vim9execute.c')
-rw-r--r-- | src/vim9execute.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/src/vim9execute.c b/src/vim9execute.c index 3c23ad411..beca9e723 100644 --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -2333,16 +2333,33 @@ load_namespace_var(ectx_T *ectx, isntype_T isn_type, isn_T *iptr) if (di == NULL) { + if (isn_type == ISN_LOADG) + { + ufunc_T *ufunc = find_func(iptr->isn_arg.string, TRUE); + + // g:Something could be a function + if (ufunc != NULL) + { + typval_T *tv = STACK_TV_BOT(0); + + ++ectx->ec_stack.ga_len; + tv->v_type = VAR_FUNC; + tv->vval.v_string = alloc(STRLEN(iptr->isn_arg.string) + 3); + if (tv->vval.v_string == NULL) + return FAIL; + STRCPY(tv->vval.v_string, "g:"); + STRCPY(tv->vval.v_string + 2, iptr->isn_arg.string); + return OK; + } + } SOURCING_LNUM = iptr->isn_lnum; - if (vim_strchr(iptr->isn_arg.string, - AUTOLOAD_CHAR) != NULL) + if (vim_strchr(iptr->isn_arg.string, AUTOLOAD_CHAR) != NULL) // no check if the item exists in the script but // isn't exported, it is too complicated - semsg(_(e_item_not_found_in_script_str), - iptr->isn_arg.string); + semsg(_(e_item_not_found_in_script_str), iptr->isn_arg.string); else semsg(_(e_undefined_variable_char_str), - namespace, iptr->isn_arg.string); + namespace, iptr->isn_arg.string); return FAIL; } else |