diff src/vim9execute.c @ 23102:3239b0f3c592 v8.2.2097

patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort Commit: https://github.com/vim/vim/commit/56602ba153af7130b76daf83933922aaea3e2646 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 5 21:22:08 2020 +0100 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort Problem: Vim9: using :silent! when calling a function prevents abortng that function. Solution: Add emsg_silent_def and did_emsg_def.
author Bram Moolenaar <Bram@vim.org>
date Sat, 05 Dec 2020 21:30:03 +0100
parents 9c3a6c33c0e5
children 6aa8ddf7a3fa
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -851,6 +851,8 @@ call_def_function(
     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,6 +1023,11 @@ call_def_function(
     // 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,8 +3015,10 @@ func_return:
 
 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)
+	// 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,6 +3065,8 @@ failed:
 	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.