Patch 8.2.2097
Problem:    Vim9: using :silent! when calling a function prevents abortng that
            function.
Solution:   Add emsg_silent_def and did_emsg_def.
Files:      src/globals.h, src/message.c, src/vim9execute.c,
            src/testdir/test_vim9_func.vim


*** ../vim-8.2.2096/src/globals.h       2020-11-20 19:26:45.081207924 +0100
--- src/globals.h       2020-12-05 21:11:19.137024148 +0100
***************
*** 230,235 ****
--- 230,237 ----
  EXTERN int    did_emsg;                   // set by emsg() when the message
                                            // is displayed or thrown
  #ifdef FEAT_EVAL
+ EXTERN int    did_emsg_def;               // set by emsg() when emsg_silent
+                                           // is set before calling a function
  EXTERN int    did_emsg_cumul;             // cumulative did_emsg, increased
                                            // when did_emsg is reset.
  EXTERN int    called_vim_beep;            // set if vim_beep() is called
***************
*** 1134,1139 ****
--- 1136,1145 ----
  
  EXTERN int    msg_silent INIT(= 0);   // don't print messages
  EXTERN int    emsg_silent INIT(= 0);  // don't print error messages
+ #ifdef FEAT_EVAL
+ EXTERN int    emsg_silent_def INIT(= 0);  // value of emsg_silent when a :def
+                                           // function is called
+ #endif
  EXTERN int    emsg_noredir INIT(= 0); // don't redirect error messages
  EXTERN int    cmd_silent INIT(= FALSE); // don't echo the command line
  
*** ../vim-8.2.2096/src/message.c       2020-12-04 19:42:48.431278293 +0100
--- src/message.c       2020-12-05 21:04:46.482387438 +0100
***************
*** 697,702 ****
--- 697,708 ----
                }
                redir_write(s, -1);
            }
+ #ifdef FEAT_EVAL
+           // Only increment did_emsg_def when :silent! wasn't used inside the
+           // :def function.
+           if (emsg_silent == emsg_silent_def)
+               ++did_emsg_def;
+ #endif
  #ifdef FEAT_JOB_CHANNEL
            ch_log(NULL, "ERROR silent: %s", (char *)s);
  #endif
*** ../vim-8.2.2096/src/vim9execute.c   2020-12-05 19:17:12.603703388 +0100
--- src/vim9execute.c   2020-12-05 21:21:44.522877071 +0100
***************
*** 851,856 ****
--- 851,858 ----
      msglist_T *private_msg_list = NULL;
      cmdmod_T  save_cmdmod;
      int               restore_cmdmod = FALSE;
+     int               save_emsg_silent_def = emsg_silent_def;
+     int               save_did_emsg_def = did_emsg_def;
      int               trylevel_at_start = trylevel;
      int               orig_funcdepth;
  
***************
*** 1021,1026 ****
--- 1023,1033 ----
      // Do turn errors into exceptions.
      suppress_errthrow = FALSE;
  
+     // When ":silent!" was used before calling then we still abort the
+     // function.  If ":silent!" is used in the function then we don't.
+     emsg_silent_def = emsg_silent;
+     did_emsg_def = 0;
+ 
      // Decide where to start execution, handles optional arguments.
      init_instr_idx(ufunc, argc, &ectx);
  
***************
*** 3008,3015 ****
  
  on_error:
        // Jump here for an error that does not require aborting execution.
!       // If "emsg_silent" is set then ignore the error.
!       if (did_emsg_cumul + did_emsg == did_emsg_before && emsg_silent)
            continue;
  on_fatal_error:
        // Jump here for an error that messes up the stack.
--- 3015,3024 ----
  
  on_error:
        // Jump here for an error that does not require aborting execution.
!       // If "emsg_silent" is set then ignore the error, unless it was set
!       // when calling the function.
!       if (did_emsg_cumul + did_emsg == did_emsg_before
!                                          && emsg_silent && did_emsg_def == 0)
            continue;
  on_fatal_error:
        // Jump here for an error that messes up the stack.
***************
*** 3056,3061 ****
--- 3065,3072 ----
        undo_cmdmod(&cmdmod);
        cmdmod = save_cmdmod;
      }
+     emsg_silent_def = save_emsg_silent_def;
+     did_emsg_def += save_did_emsg_def;
  
  failed_early:
      // Free all local variables, but not arguments.
*** ../vim-8.2.2096/src/testdir/test_vim9_func.vim      2020-12-05 
19:17:12.603703388 +0100
--- src/testdir/test_vim9_func.vim      2020-12-05 19:18:27.559521523 +0100
***************
*** 1784,1789 ****
--- 1784,1805 ----
    delfunc! g:Func
  enddef
  
+ def Test_abort_with_silent_call()
+   var lines =<< trim END
+       vim9script
+       g:result = 'none'
+       def Func()
+         g:result += 3
+         g:result = 'yes'
+       enddef
+       # error is silenced, but function aborts on error
+       silent! Func()
+       assert_equal('none', g:result)
+       unlet g:result
+   END
+   CheckScriptSuccess(lines)
+ enddef
+ 
  def Test_continues_with_silent_error()
    var lines =<< trim END
        vim9script
*** ../vim-8.2.2096/src/version.c       2020-12-05 19:17:12.603703388 +0100
--- src/version.c       2020-12-05 21:20:52.835053933 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2097,
  /**/

-- 
I wonder, do vegetarians eat fruit bats?

 /// 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/202012052022.0B5KMY1F909384%40masaka.moolenaar.net.

Raspunde prin e-mail lui