Mercurial > vim
changeset 26472:cc95e10e1cf2 v8.2.3766
patch 8.2.3766: converting a funcref to a string leaves out "g:"
Commit: https://github.com/vim/vim/commit/c4ec338fb80ebfb5d631f0718fdd1a1c04d9ed82
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 9 16:40:18 2021 +0000
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 Dec 2021 17:45:04 +0100 |
parents | d76f275bc6dc |
children | a8195907f08e |
files | src/eval.c src/testdir/test_functions.vim src/version.c |
diffstat | 3 files changed, 16 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -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)
--- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -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