]> granicus.if.org Git - vim/commitdiff
patch 8.2.5167: get(Fn, 'name') on funcref returns special byte code v8.2.5167
authorBram Moolenaar <Bram@vim.org>
Mon, 27 Jun 2022 10:45:52 +0000 (11:45 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 27 Jun 2022 10:45:52 +0000 (11:45 +0100)
Problem:    get(Fn, 'name') on funcref returns special byte code.
Solution:   Use the printable name.

src/evalfunc.c
src/testdir/test_getvar.vim
src/version.c

index 39706cd8f2613b3adb707cc0da0e7d0fc866120f..cb12a46c3fe1b7d1836dc6ecfcbbba46520c01d9 100644 (file)
@@ -4719,19 +4719,23 @@ f_get(typval_T *argvars, typval_T *rettv)
        if (pt != NULL)
        {
            char_u *what = tv_get_string(&argvars[1]);
-           char_u *n;
 
            if (STRCMP(what, "func") == 0 || STRCMP(what, "name") == 0)
            {
+               char_u *name = partial_name(pt);
+
                rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING);
-               n = partial_name(pt);
-               if (n == NULL)
+               if (name == NULL)
                    rettv->vval.v_string = NULL;
                else
                {
-                   rettv->vval.v_string = vim_strsave(n);
                    if (rettv->v_type == VAR_FUNC)
-                       func_ref(rettv->vval.v_string);
+                       func_ref(name);
+                   if (*what == 'n' && pt->pt_name == NULL
+                                                       && pt->pt_func != NULL)
+                       // use <SNR> instead of the byte code
+                       name = printable_func_name(pt->pt_func);
+                   rettv->vval.v_string = vim_strsave(name);
                }
            }
            else if (STRCMP(what, "dict") == 0)
index c82fdd5cc67c88b02f9fddc24a0d2fc8b48f95b3..2065186a5ad52ddce3ce0d7f15dffcde0cf8b35d 100644 (file)
@@ -134,11 +134,20 @@ func Test_get_lambda()
   call assert_equal([], get(l:L, 'args'))
 endfunc
 
+func s:FooBar()
+endfunc
+
 " get({func}, {what} [, {default}])
 func Test_get_func()
   let l:F = function('tr')
   call assert_equal('tr', get(l:F, 'name'))
   call assert_equal(l:F, get(l:F, 'func'))
+
+  let Fb_func = function('s:FooBar')
+  call assert_match('<SNR>\d\+_FooBar', get(Fb_func, 'name'))
+  let Fb_ref = funcref('s:FooBar')
+  call assert_match('<SNR>\d\+_FooBar', get(Fb_ref, 'name'))
+
   call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'}))
   call assert_equal(0, get(l:F, 'dict'))
   call assert_equal([], get(l:F, 'args'))
index 3422e7aaf87f634319a55a6d6994222133d867e5..d9dba16a73b573f855fb73b2875520f0e1bee8c5 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    5167,
 /**/
     5166,
 /**/