comparison src/vim9execute.c @ 27841:5ce69c07a106 v8.2.4446

patch 8.2.4446: Vim9: cannot refer to a global function like a local one Commit: https://github.com/vim/vim/commit/fe73255c92b6cb54851f82fa32458340b736298d Author: Bram Moolenaar <Bram@vim.org> Date: Tue Feb 22 19:39:13 2022 +0000 patch 8.2.4446: Vim9: cannot refer to a global function like a local one 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)
author Bram Moolenaar <Bram@vim.org>
date Tue, 22 Feb 2022 20:45:04 +0100
parents 89b1bc6fd40a
children 7d70b420de00
comparison
equal deleted inserted replaced
27840:a93a7405f2e2 27841:5ce69c07a106
2331 } 2331 }
2332 di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE); 2332 di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
2333 2333
2334 if (di == NULL) 2334 if (di == NULL)
2335 { 2335 {
2336 if (isn_type == ISN_LOADG)
2337 {
2338 ufunc_T *ufunc = find_func(iptr->isn_arg.string, TRUE);
2339
2340 // g:Something could be a function
2341 if (ufunc != NULL)
2342 {
2343 typval_T *tv = STACK_TV_BOT(0);
2344
2345 ++ectx->ec_stack.ga_len;
2346 tv->v_type = VAR_FUNC;
2347 tv->vval.v_string = alloc(STRLEN(iptr->isn_arg.string) + 3);
2348 if (tv->vval.v_string == NULL)
2349 return FAIL;
2350 STRCPY(tv->vval.v_string, "g:");
2351 STRCPY(tv->vval.v_string + 2, iptr->isn_arg.string);
2352 return OK;
2353 }
2354 }
2336 SOURCING_LNUM = iptr->isn_lnum; 2355 SOURCING_LNUM = iptr->isn_lnum;
2337 if (vim_strchr(iptr->isn_arg.string, 2356 if (vim_strchr(iptr->isn_arg.string, AUTOLOAD_CHAR) != NULL)
2338 AUTOLOAD_CHAR) != NULL)
2339 // no check if the item exists in the script but 2357 // no check if the item exists in the script but
2340 // isn't exported, it is too complicated 2358 // isn't exported, it is too complicated
2341 semsg(_(e_item_not_found_in_script_str), 2359 semsg(_(e_item_not_found_in_script_str), iptr->isn_arg.string);
2342 iptr->isn_arg.string);
2343 else 2360 else
2344 semsg(_(e_undefined_variable_char_str), 2361 semsg(_(e_undefined_variable_char_str),
2345 namespace, iptr->isn_arg.string); 2362 namespace, iptr->isn_arg.string);
2346 return FAIL; 2363 return FAIL;
2347 } 2364 }
2348 else 2365 else
2349 { 2366 {
2350 copy_tv(&di->di_tv, STACK_TV_BOT(0)); 2367 copy_tv(&di->di_tv, STACK_TV_BOT(0));