0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.3766: converting a funcref to a string leaves out "g:"

Problem:    Converting a funcref to a string leaves out "g:", causing the
            meaning of the name depending on the context.
Solution:   Prepend "g:" for a global function.
This commit is contained in:
Bram Moolenaar
2021-12-09 16:40:18 +00:00
parent dcb53be441
commit c4ec338fb8
3 changed files with 16 additions and 1 deletions

View File

@@ -5006,6 +5006,14 @@ echo_string_core(
ga_concat(&ga, (char_u *)"function(");
if (fname != NULL)
{
// When using uf_name prepend "g:" for a global function.
if (pt->pt_name == NULL && fname[0] == '\''
&& vim_isupper(fname[1]))
{
ga_concat(&ga, (char_u *)"'g:");
ga_concat(&ga, fname + 1);
}
else
ga_concat(&ga, fname);
vim_free(fname);
}

View File

@@ -2771,5 +2771,10 @@ func Test_builtin_check()
call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
endfunc
func Test_funcref_to_string()
let Fn = funcref('g:Test_funcref_to_string')
call assert_equal("function('g:Test_funcref_to_string')", string(Fn))
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3766,
/**/
3765,
/**/