# HG changeset patch # User Bram Moolenaar # Date 1647025203 -3600 # Node ID b10fa9b17c8599b043baf0debb4652fe0e1b9c27 # Parent e0b5ccdea95f4c87e32ad3de31d8d26150bb79aa patch 8.2.4548: script-local function is deleted when used in a funcref Commit: https://github.com/vim/vim/commit/fb43cfc2c6a003b850343bfd27cb3059c734d7d4 Author: Bram Moolenaar Date: Fri Mar 11 18:54:17 2022 +0000 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 "" reference counted. (closes #9916, closes #9820) diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -3717,6 +3717,24 @@ def Test_nested_closure_in_dict() v9.CheckScriptSuccess(lines) enddef +def Test_script_local_other_script() + var lines =<< trim END + function LegacyJob() + let FuncRef = function('s:close_cb') + endfunction + function s:close_cb(...) + endfunction + END + lines->writefile('Xlegacy.vim') + source Xlegacy.vim + g:LegacyJob() + g:LegacyJob() + g:LegacyJob() + + delfunc g:LegacyJob + delete('Xlegacy.vim') +enddef + def Test_check_func_arg_types() var lines =<< trim END vim9script diff --git a/src/userfunc.c b/src/userfunc.c --- a/src/userfunc.c +++ b/src/userfunc.c @@ -2215,8 +2215,9 @@ numbered_function(char_u *name) /* * There are two kinds of function names: - * 1. ordinary names, function defined with :function or :def - * 2. numbered functions and lambdas + * 1. ordinary names, function defined with :function or :def; + * can start with "123_" literally or with K_SPECIAL. + * 2. Numbered functions and lambdas: "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. @@ -2224,7 +2225,7 @@ numbered_function(char_u *name) int func_name_refcount(char_u *name) { - return numbered_function(name) || *name == '<'; + return numbered_function(name) || (name[0] == '<' && name[1] == 'l'); } /* diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4548, +/**/ 4547, /**/ 4546,