From 92e51d7e4b79913434c7b74a275babcf65098b97 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 19 Nov 2022 12:47:44 +0800 Subject: vim-patch:8.2.5167: get(Fn, 'name') on funcref returns special byte code (#21112) Problem: get(Fn, 'name') on funcref returns special byte code. Solution: Use the printable name. https://github.com/vim/vim/commit/1ae8c262df7083dfb4b41485508951c50eccc84c Cherry-pick printable_func_name() from patch 8.2.0149. Co-authored-by: Bram Moolenaar --- src/nvim/eval/funcs.c | 12 ++++++++---- src/nvim/eval/userfunc.c | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'src/nvim/eval') diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 244802a183..12568ec965 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2528,13 +2528,17 @@ static void f_get(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) const char *const what = tv_get_string(&argvars[1]); if (strcmp(what, "func") == 0 || strcmp(what, "name") == 0) { + const char *name = (const char *)partial_name(pt); rettv->v_type = (*what == 'f' ? VAR_FUNC : VAR_STRING); - const char *const n = (const char *)partial_name(pt); - assert(n != NULL); - rettv->vval.v_string = xstrdup(n); + assert(name != NULL); if (rettv->v_type == VAR_FUNC) { - func_ref((char_u *)rettv->vval.v_string); + func_ref((char_u *)name); } + if (*what == 'n' && pt->pt_name == NULL && pt->pt_func != NULL) { + // use instead of the byte code + name = (const char *)printable_func_name(pt->pt_func); + } + rettv->vval.v_string = xstrdup(name); } else if (strcmp(what, "dict") == 0) { what_is_dict = true; if (pt->pt_dict != NULL) { diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index 893a4c77eb..ae867cb716 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -1652,6 +1652,11 @@ theend: return ret; } +char_u *printable_func_name(ufunc_T *fp) +{ + return fp->uf_name_exp != NULL ? fp->uf_name_exp : fp->uf_name; +} + /// List the head of the function: "name(arg1, arg2)". /// /// @param[in] fp Function pointer. -- cgit