Skip to content

Commit

Permalink
patch 8.2.3766: converting a funcref to a string leaves out "g:"
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
brammool committed Dec 9, 2021
1 parent dcb53be commit c4ec338
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/eval.c
Expand Up @@ -5006,7 +5006,15 @@ echo_string_core(
ga_concat(&ga, (char_u *)"function(");
if (fname != NULL)
{
ga_concat(&ga, fname);
// 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);
}
if (pt != NULL && pt->pt_argc > 0)
Expand Down
5 changes: 5 additions & 0 deletions src/testdir/test_functions.vim
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -753,6 +753,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3766,
/**/
3765,
/**/
Expand Down

0 comments on commit c4ec338

Please sign in to comment.