Skip to content

Commit 1ae8c26

Browse files
committed
patch 8.2.5167: get(Fn, 'name') on funcref returns special byte code
Problem: get(Fn, 'name') on funcref returns special byte code. Solution: Use the printable name.
1 parent f65cc66 commit 1ae8c26

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/evalfunc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4719,19 +4719,23 @@ f_get(typval_T *argvars, typval_T *rettv)
47194719
if (pt != NULL)
47204720
{
47214721
char_u *what = tv_get_string(&argvars[1]);
4722-
char_u *n;
47234722

47244723
if (STRCMP(what, "func") == 0 || STRCMP(what, "name") == 0)
47254724
{
4725+
char_u *name = partial_name(pt);
4726+
47264727
rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING);
4727-
n = partial_name(pt);
4728-
if (n == NULL)
4728+
if (name == NULL)
47294729
rettv->vval.v_string = NULL;
47304730
else
47314731
{
4732-
rettv->vval.v_string = vim_strsave(n);
47334732
if (rettv->v_type == VAR_FUNC)
4734-
func_ref(rettv->vval.v_string);
4733+
func_ref(name);
4734+
if (*what == 'n' && pt->pt_name == NULL
4735+
&& pt->pt_func != NULL)
4736+
// use <SNR> instead of the byte code
4737+
name = printable_func_name(pt->pt_func);
4738+
rettv->vval.v_string = vim_strsave(name);
47354739
}
47364740
}
47374741
else if (STRCMP(what, "dict") == 0)

src/testdir/test_getvar.vim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,20 @@ func Test_get_lambda()
134134
call assert_equal([], get(l:L, 'args'))
135135
endfunc
136136

137+
func s:FooBar()
138+
endfunc
139+
137140
" get({func}, {what} [, {default}])
138141
func Test_get_func()
139142
let l:F = function('tr')
140143
call assert_equal('tr', get(l:F, 'name'))
141144
call assert_equal(l:F, get(l:F, 'func'))
145+
146+
let Fb_func = function('s:FooBar')
147+
call assert_match('<SNR>\d\+_FooBar', get(Fb_func, 'name'))
148+
let Fb_ref = funcref('s:FooBar')
149+
call assert_match('<SNR>\d\+_FooBar', get(Fb_ref, 'name'))
150+
142151
call assert_equal({'func has': 'no dict'}, get(l:F, 'dict', {'func has': 'no dict'}))
143152
call assert_equal(0, get(l:F, 'dict'))
144153
call assert_equal([], get(l:F, 'args'))

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
5167,
738740
/**/
739741
5166,
740742
/**/

0 commit comments

Comments
 (0)