Patch 8.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)
Files: src/vim9execute.c, src/testdir/test_vim9_builtin.vim
*** ../vim-8.2.4445/src/vim9execute.c 2022-02-18 13:24:48.450046820 +0000
--- src/vim9execute.c 2022-02-22 19:34:38.158687631 +0000
***************
*** 2333,2348 ****
if (di == NULL)
{
SOURCING_LNUM = iptr->isn_lnum;
! 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);
else
semsg(_(e_undefined_variable_char_str),
! namespace, iptr->isn_arg.string);
return FAIL;
}
else
--- 2333,2365 ----
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)
// 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);
else
semsg(_(e_undefined_variable_char_str),
! namespace, iptr->isn_arg.string);
return FAIL;
}
else
*** ../vim-8.2.4445/src/testdir/test_vim9_builtin.vim 2022-02-22 15:12:10.667151754 +0000
--- src/testdir/test_vim9_builtin.vim 2022-02-22 19:36:49.550532426 +0000
***************
*** 427,432 ****
--- 427,447 ----
call('reverse', [l])
l->assert_equal([1, 2, 3])
+ var lines =<< trim END
+ vim9script
+ def Outer()
+ def g:Inner()
+ g:done = 'Inner'
+ enddef
+ call(g:Inner, [])
+ enddef
+ Outer()
+ assert_equal('Inner', g:done)
+ unlet g:done
+ END
+ v9.CheckScriptSuccess(lines)
+ delfunc g:Inner
+
v9.CheckDefExecAndScriptFailure(['call(123, [2])'], 'E1256: String or function required for argument 1')
v9.CheckDefExecAndScriptFailure(['call(true, [2])'], 'E1256: String or function required for argument 1')
v9.CheckDefAndScriptFailure(['call("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
*** ../vim-8.2.4445/src/version.c 2022-02-22 18:48:07.489297350 +0000
--- src/version.c 2022-02-22 19:29:30.839037740 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4446,
/**/
--
% cat /usr/include/real_life.h
void life(void);
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///