]> granicus.if.org Git - vim/commitdiff
patch 8.2.4548: script-local function is deleted when used in a funcref v8.2.4548
authorBram Moolenaar <Bram@vim.org>
Fri, 11 Mar 2022 18:54:17 +0000 (18:54 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 11 Mar 2022 18:54:17 +0000 (18:54 +0000)
Problem:    Script-local function is deleted when used in a funcref.
Solution:   Do not consider a function starting with "<SNR>" reference
            counted. (closes #9916, closes #9820)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index 85e8e9d3dd3819de52b43fc2549212f268872485..43fc68ef71e8be918b3e73151ec2c14433e8f485 100644 (file)
@@ -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
index 42e1e89bc369e3605912304a7ca3f330001b51c9..6a5d84bfd51d6905dcdbd20a1c5808f5dbdcff8d 100644 (file)
@@ -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 "<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.
@@ -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');
 }
 
 /*
index eec3622c5d485424a7c935dba916d876bc4bd191..2efc6bff354982fd312a2dec4b090b9ec2af068c 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4548,
 /**/
     4547,
 /**/