]> granicus.if.org Git - vim/commitdiff
patch 8.2.3766: converting a funcref to a string leaves out "g:" v8.2.3766
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Dec 2021 16:40:18 +0000 (16:40 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Dec 2021 16:40:18 +0000 (16:40 +0000)
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.

src/eval.c
src/testdir/test_functions.vim
src/version.c

index bc4db2906c60a92411b7ffcf09a5dc57d3f483fe..1e2e4c47686992ba9c0f9a9307011ed7998cb243 100644 (file)
@@ -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)
index ac9bb4cfabdd98b78e74e8418344e681b16805cb..a215667964dd3d6eeb83f319407b1690f0014c01 100644 (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
index 083c111f0e0625117b261c6e5842cab8861f03f7..0199acade29b89722decc1225b7b23f2864ed567 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3766,
 /**/
     3765,
 /**/