Patch 8.2.3798
Problem:    A :def callback function postpones an error message.
Solution:   Display the error after calling the function. (closes #9340)
Files:      src/userfunc.c, src/testdir/test_vim9_func.vim,
            src/testdir/dumps/Test_opfunc_error.dump


*** ../vim-8.2.3797/src/userfunc.c      2021-12-13 14:26:40.996627748 +0000
--- src/userfunc.c      2021-12-13 18:12:33.965033362 +0000
***************
*** 3173,3178 ****
--- 3173,3187 ----
      ++callback_depth;
      ret = call_func(callback->cb_name, len, rettv, argcount, argvars, 
&funcexe);
      --callback_depth;
+ 
+     // When a :def function was called that uses :try an error would be turned
+     // into an exception.  Need to give the error here.
+     if (need_rethrow && current_exception != NULL)
+     {
+       need_rethrow = FALSE;
+       handle_did_throw();
+     }
+ 
      return ret;
  }
  
*** ../vim-8.2.3797/src/testdir/test_vim9_func.vim      2021-12-13 
11:31:00.488529501 +0000
--- src/testdir/test_vim9_func.vim      2021-12-13 18:11:54.585094633 +0000
***************
*** 2763,2787 ****
  
  func Test_silent_echo()
    CheckScreendump
  
!   let lines =<< trim END
      vim9script
      def EchoNothing()
        silent echo ''
      enddef
      defcompile
    END
!   call writefile(lines, 'XTest_silent_echo')
  
!   " Check that the balloon shows up after a mouse move
!   let buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
!   call term_sendkeys(buf, ":abc")
!   call VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
! 
!   " clean up
!   call StopVimInTerminal(buf)
!   call delete('XTest_silent_echo')
! endfunc
  
  def SilentlyError()
    execute('silent! invalid')
--- 2763,2790 ----
  
  func Test_silent_echo()
    CheckScreendump
+   call Run_Test_silent_echo()
+ endfunc
  
! def Run_Test_silent_echo()
!   var lines =<< trim END
      vim9script
      def EchoNothing()
        silent echo ''
      enddef
      defcompile
    END
!   writefile(lines, 'XTest_silent_echo')
  
!   # Check that the balloon shows up after a mouse move
!   var buf = RunVimInTerminal('-S XTest_silent_echo', {'rows': 6})
!   term_sendkeys(buf, ":abc")
!   VerifyScreenDump(buf, 'Test_vim9_silent_echo', {})
! 
!   # clean up
!   StopVimInTerminal(buf)
!   delete('XTest_silent_echo')
! enddef
  
  def SilentlyError()
    execute('silent! invalid')
***************
*** 3165,3170 ****
--- 3168,3208 ----
    nunmap <F3>
  enddef
  
+ func Test_opfunc_error()
+   CheckScreendump
+   call Run_Test_opfunc_error()
+ endfunc
+ 
+ def Run_Test_opfunc_error()
+   # test that the error from Opfunc() is displayed right away
+   var lines =<< trim END
+       vim9script
+ 
+       def Opfunc(type: string)
+         try
+           eval [][0]
+         catch /nothing/  # error not caught
+         endtry
+       enddef
+       &operatorfunc = Opfunc
+       nnoremap <expr> l <SID>L()
+       def L(): string
+         return 'l'
+       enddef
+       'x'->repeat(10)->setline(1)
+       feedkeys('g@l', 'n')
+       feedkeys('llll')
+   END
+   call writefile(lines, 'XTest_opfunc_error')
+ 
+   var buf = RunVimInTerminal('-S XTest_opfunc_error', {rows: 6, 
wait_for_ruler: 0})
+   VerifyScreenDump(buf, 'Test_opfunc_error', {})
+ 
+   # clean up
+   StopVimInTerminal(buf)
+   delete('XTest_opfunc_error')
+ enddef
+ 
  " this was crashing on exit
  def Test_nested_lambda_in_closure()
    var lines =<< trim END
*** ../vim-8.2.3797/src/testdir/dumps/Test_opfunc_error.dump    2021-12-13 
18:13:53.664909396 +0000
--- src/testdir/dumps/Test_opfunc_error.dump    2021-12-13 18:06:41.777582524 
+0000
***************
*** 0 ****
--- 1,6 ----
+ |~+0#4040ff13#ffffff0| @73
+ |~| @73
+ |E+0#ffffff16#e000002|r@1|o|r| |d|e|t|e|c|t|e|d| |w|h|i|l|e| 
|p|r|o|c|e|s@1|i|n|g| |f|u|n|c|t|i|o|n| |<|S|N|R|>|9|_|O|p|f|u|n|c|:| 
+0#0000000#ffffff0@19
+ |l+0#af5f00255&|i|n|e| @3|2|:| +0#0000000&@64
+ |E+0#ffffff16#e000002|6|8|4|:| |l|i|s|t| |i|n|d|e|x| |o|u|t| |o|f| 
|r|a|n|g|e|:| |0| +0#0000000#ffffff0@42
+ |P+0#00e0003&|r|e|s@1| |E|N|T|E|R| |o|r| |t|y|p|e| |c|o|m@1|a|n|d| |t|o| 
|c|o|n|t|i|n|u|e> +0#0000000&@35
*** ../vim-8.2.3797/src/version.c       2021-12-13 14:40:50.026907587 +0000
--- src/version.c       2021-12-13 17:45:25.095607083 +0000
***************
*** 751,752 ****
--- 751,754 ----
  {   /* Add new patch number below this line */
+ /**/
+     3798,
  /**/

-- 
The technology involved in making anything invisible is so infinitely
complex that nine hundred and ninety-nine billion, nine hundred and
ninety-nine million, nine hundred and ninety-nine thousand, nine hundred
and ninety-nine times out of a trillion it is much simpler and more
effective just to take the thing away and do without it.
                -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

 /// 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/20211213182016.141F21C0D69%40moolenaar.net.

Raspunde prin e-mail lui