diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-06-27 11:45:52 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-06-27 11:45:52 +0100 |
commit | 1ae8c262df7083dfb4b41485508951c50eccc84c (patch) | |
tree | 032508bde4e3e7c31f9e52dddc2f83759a32c46e | |
parent | f65cc665fa751bad3ffe75f58ce1251d6695949f (diff) | |
download | vim-git-1ae8c262df7083dfb4b41485508951c50eccc84c.tar.gz |
patch 8.2.5167: get(Fn, 'name') on funcref returns special byte codev8.2.5167
Problem: get(Fn, 'name') on funcref returns special byte code.
Solution: Use the printable name.
-rw-r--r-- | src/evalfunc.c | 14 | ||||
-rw-r--r-- | src/testdir/test_getvar.vim | 9 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 20 insertions, 5 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 39706cd8f..cb12a46c3 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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) diff --git a/src/testdir/test_getvar.vim b/src/testdir/test_getvar.vim index c82fdd5cc..2065186a5 100644 --- a/src/testdir/test_getvar.vim +++ b/src/testdir/test_getvar.vim @@ -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')) diff --git a/src/version.c b/src/version.c index 3422e7aaf..d9dba16a7 100644 --- a/src/version.c +++ b/src/version.c @@ -736,6 +736,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 5167, +/**/ 5166, /**/ 5165, |