Patch 8.2.1706
Problem:    Vim9: crash after running into the "Multiple closures" error.
Solution:   When a function fails still update any closures. (closes #6973)
Files:      src/vim9execute.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1705/src/vim9execute.c   2020-09-17 21:28:59.939951846 +0200
--- src/vim9execute.c   2020-09-18 21:23:08.323468431 +0200
***************
*** 2676,2690 ****
        continue;
  
  func_return:
!       // Restore previous function. If the frame pointer is zero 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;
--- 2676,2686 ----
        continue;
  
  func_return:
!       // 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)
            goto done;
! 
        if (func_return(&ectx) == FAIL)
            // only fails when out of memory
            goto failed;
***************
*** 2703,2708 ****
--- 2699,2708 ----
      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);
*** ../vim-8.2.1705/src/testdir/test_vim9_func.vim      2020-09-16 
23:23:33.026882158 +0200
--- src/testdir/test_vim9_func.vim      2020-09-18 21:22:45.115547868 +0200
***************
*** 1294,1299 ****
--- 1294,1313 ----
    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()
*** ../vim-8.2.1705/src/version.c       2020-09-18 19:40:41.670037639 +0200
--- src/version.c       2020-09-18 21:24:32.943178148 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     1706,
  /**/

-- 
SOLDIER: Where did you get the coconuts?
ARTHUR:  Through ... We found them.
SOLDIER: Found them?  In Mercea.  The coconut's tropical!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202009181926.08IJQ2BB2743699%40masaka.moolenaar.net.

Raspunde prin e-mail lui