Patch 8.2.2810
Problem:    Vim9: crash when calling a function in a substitute expression.
Solution:   Set the instructions back to the substitute expression
            instrunctions. (closes #8148)
Files:      src/vim9execute.c, src/testdir/test_vim9_cmd.vim


*** ../vim-8.2.2809/src/vim9execute.c   2021-04-20 22:16:35.355248931 +0200
--- src/vim9execute.c   2021-04-25 14:39:14.067244567 +0200
***************
*** 601,606 ****
--- 601,612 ----
                                       + STACK_FRAME_IDX_OFF)->vval.v_number;
      ectx->ec_instr = INSTRUCTIONS(prev_dfunc);
  
+     // If the call was inside an ISN_SUBSTITUTE instruction need to use its
+     // list of instructions.
+     if (ectx->ec_instr[ectx->ec_iidx - 1].isn_type == ISN_SUBSTITUTE)
+       ectx->ec_instr = ectx->ec_instr[ectx->ec_iidx - 1]
+                                                     .isn_arg.subs.subs_instr;
+ 
      if (floc == NULL)
        ectx->ec_funclocal.floc_restore_cmdmod = FALSE;
      else
*** ../vim-8.2.2809/src/testdir/test_vim9_cmd.vim       2021-04-21 
16:00:06.711976510 +0200
--- src/testdir/test_vim9_cmd.vim       2021-04-25 14:47:07.125192407 +0200
***************
*** 1194,1203 ****
    endfor
    assert_equal('yes no abc', getline(1))
  
    CheckDefFailure(['s/from/\="x")/'], 'E488:')
    CheckDefFailure(['s/from/\="x"/9'], 'E488:')
  
!   bwipe!
  enddef
  
  def Test_redir_to_var()
--- 1194,1224 ----
    endfor
    assert_equal('yes no abc', getline(1))
  
+   bwipe!
+ 
    CheckDefFailure(['s/from/\="x")/'], 'E488:')
    CheckDefFailure(['s/from/\="x"/9'], 'E488:')
  
!   # When calling a function the right instruction list needs to be restored.
!   var lines =<< trim END
!       vim9script
!       def Foo()
!           Bar([])
!       enddef
!       def Bar(l: list<number>)
!           s/^/\=Rep()/
!           for n in l[:]
!           endfor
!       enddef
!       def Rep(): string
!           return 'rep'
!       enddef
!       new
!       Foo()
!       assert_equal('rep', getline(1))
!       bwipe!
!   END
!   CheckScriptSuccess(lines)
  enddef
  
  def Test_redir_to_var()
*** ../vim-8.2.2809/src/version.c       2021-04-25 13:54:38.992836747 +0200
--- src/version.c       2021-04-25 14:44:18.417893652 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2810,
  /**/

-- 
Living in Hollywood is like living in a bowl of granola.  What ain't
fruits and nuts is flakes.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/202104251249.13PCndkI2179428%40masaka.moolenaar.net.

Raspunde prin e-mail lui