]> granicus.if.org Git - vim/commitdiff
patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error v8.2.1706
authorBram Moolenaar <Bram@vim.org>
Fri, 18 Sep 2020 19:25:32 +0000 (21:25 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 18 Sep 2020 19:25:32 +0000 (21:25 +0200)
Problem:    Vim9: crash after running into the "Multiple closures" error.
Solution:   When a function fails still update any closures. (closes #6973)

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

index f3aae7c6caa399cf7a1edbe90ef286a46ee0b4c6..8c2349c34340c31994dad6dad79ce184de50b682 100644 (file)
@@ -1294,6 +1294,20 @@ def Test_call_closure_not_compiled()
   GetResult(g:Ref)->assert_equal('sometext')
 enddef
 
+def Test_double_closure_fails()
+  let lines =<< trim END
+    vim9script
+    def Func()
+    let var = 0
+    for i in range(2)
+       timer_start(0, {-> var})
+    endfor
+    enddef
+    Func()
+  END
+  CheckScriptFailure(lines, 'Multiple closures not supported yet')
+enddef
+
 def Test_sort_return_type()
   let res: list<number>
   res = [1, 2, 3]->sort()
index e47f0d19a4dac6d7458a96270c5d28ec5436aecf..93f770144a9a5f3396490cd38fd2a84f3782eb9f 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1706,
 /**/
     1705,
 /**/
index 4332c03ed9e8affe3204401e8910ad6b7836074a..5fe587892f2999faa175e0f217e367b9cb498607 100644 (file)
@@ -2676,15 +2676,11 @@ call_def_function(
        continue;
 
 func_return:
-       // Restore previous function. If the frame pointer is zero then there
-       // is none and we are done.
+       // Restore previous function. If the frame pointer is where we started
+       // then there is none and we are done.
        if (ectx.ec_frame_idx == initial_frame_idx)
-       {
-           if (handle_closure_in_use(&ectx, FALSE) == FAIL)
-               // only fails when out of memory
-               goto failed;
            goto done;
-       }
+
        if (func_return(&ectx) == FAIL)
            // only fails when out of memory
            goto failed;
@@ -2703,6 +2699,10 @@ done:
     ret = OK;
 
 failed:
+    // Also deal with closures when failed, they may already be in use
+    // somewhere.
+    handle_closure_in_use(&ectx, FALSE);
+
     // When failed need to unwind the call stack.
     while (ectx.ec_frame_idx != initial_frame_idx)
        func_return(&ectx);