]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4321: Vim9: crash when using a funcref to a closure v8.2.4321
authorBram Moolenaar <Bram@vim.org>
Mon, 7 Feb 2022 17:50:39 +0000 (17:50 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 7 Feb 2022 17:50:39 +0000 (17:50 +0000)
Problem:    Vim9: crash when using a funcref to a closure.
Solution:   Copy pt_outer to the new partial. (closes #9714)

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

index 3cc95c9884c907eb69a9b25466d6b1db21f18a4e..eb12e75d07a3d34607e26aa6f7ca67ab554e0dbb 100644 (file)
@@ -4454,6 +4454,9 @@ common_function(typval_T *argvars, typval_T *rettv, int is_funcref)
                    pt->pt_name = name;
                    func_ref(name);
                }
+
+               if (arg_pt != NULL)
+                   pt->pt_outer = arg_pt->pt_outer;
            }
            rettv->v_type = VAR_PARTIAL;
            rettv->vval.v_partial = pt;
index e781a21a145f37034c234254633afb7d1a1668a2..7ab15f72f3174b941d38cd29e8f5fe70b9b63d14 100644 (file)
@@ -3455,6 +3455,28 @@ def Test_nested_lambda_in_closure()
   delete('XnestedDone')
 enddef
 
+def Test_nested_closure_funcref()
+  var lines =<< trim END
+      vim9script
+      def Func()
+          var n: number
+          def Nested()
+              ++n
+          enddef
+          Nested()
+          g:result_one = n
+          var Ref = function(Nested)
+          Ref()
+          g:result_two = n
+      enddef
+      Func()
+  END
+  v9.CheckScriptSuccess(lines)
+  assert_equal(1, g:result_one)
+  assert_equal(2, g:result_two)
+  unlet g:result_one g:result_two
+enddef
+
 def Test_check_func_arg_types()
   var lines =<< trim END
       vim9script
index 4fdeb2fdeb29e5061061e1eaad37f4a197d65f26..97bcfdef9bd9894e2044d80cc1056ccd3077c94c 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4321,
 /**/
     4320,
 /**/