commit 2ba44af7e05d553770a35e8717c5873458d03706
parent ffb45263767d6b1bbbb34a8aedcb24fd26bd0bd1
Author: Jan Edmund Lazo <jan.lazo@mail.utoronto.ca>
Date: Fri, 19 Dec 2025 00:55:40 -0500
vim-patch:8.2.4548: script-local function is deleted when used in a funcref
Problem: Script-local function is deleted when used in a funcref.
Solution: Do not consider a function starting with "<SNR>" reference
counted. (closes vim/vim#9916, closes vim/vim#9820)
https://github.com/vim/vim/commit/fb43cfc2c6a003b850343bfd27cb3059c734d7d4
Co-authored-by: Bram Moolenaar <Bram@vim.org>
Co-authored-by: zeertzjq <zeertzjq@outlook.com>
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c
@@ -1370,14 +1370,16 @@ void call_user_func(ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rett
}
/// There are two kinds of function names:
-/// 1. ordinary names, function defined with :function
-/// 2. numbered functions and lambdas
+/// 1. ordinary names, function defined with :function;
+/// can start with "<SNR>123_" literally or with K_SPECIAL.
+/// 2. Numbered functions and lambdas: "<lambda>123"
/// For the first we only count the name stored in func_hashtab as a reference,
/// using function() does not count as a reference, because the function is
/// looked up by name.
static bool func_name_refcount(const char *name)
+ FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
{
- return isdigit((uint8_t)(*name)) || *name == '<';
+ return isdigit((uint8_t)(*name)) || (name[0] == '<' && name[1] == 'l');
}
/// Check the argument count for user function "fp".