]> granicus.if.org Git - vim/commitdiff
patch 8.2.2743: Vim9: function state stuck when compiling with ":silent!" v8.2.2743
authorBram Moolenaar <Bram@vim.org>
Sat, 10 Apr 2021 12:03:43 +0000 (14:03 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 10 Apr 2021 12:03:43 +0000 (14:03 +0200)
Problem:    Vim9: function state stuck when compiling with ":silent!".
Solution:   Check for uf_def_status to be UF_COMPILING.

src/globals.h
src/message.c
src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 94ec54b9aa08b60ab219d189c4445c600186c17a..51a69465c70a418ab0f481b8431ad31dd3c17aec 100644 (file)
@@ -230,6 +230,9 @@ EXTERN int  did_endif INIT(= FALSE);    // just had ":endif"
 EXTERN int     did_emsg;                   // set by emsg() when the message
                                            // is displayed or thrown
 #ifdef FEAT_EVAL
+EXTERN int     did_emsg_silent INIT(= 0);  // incremented by emsg() when
+                                           // emsg_silent was set and did_emsg
+                                           // is not incremented
 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
index 07c3943ab4dab3d913eac909201dded1ae0cdb2f..f2fe23b58239b1be0c3d9bf200029a044f306751 100644 (file)
@@ -685,6 +685,9 @@ emsg_core(char_u *s)
         */
        if (emsg_silent != 0)
        {
+#ifdef FEAT_EVAL
+           ++did_emsg_silent;
+#endif
            if (emsg_noredir == 0)
            {
                msg_start();
index 6a3dfbbe6dc8588ff18f36b959c8cd36d8606712..e254f44b73ad71c0a0c660fae63b7b80c15c9722 100644 (file)
@@ -2603,6 +2603,20 @@ def Test_compile_error()
 
   # Second call won't try compiling again
   assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
+  delfunc g:Broken
+
+  # No error when compiling with :silent!
+  lines =<< trim END
+    def g:Broken()
+      echo 'a' + []
+    enddef
+    silent! defcompile
+  END
+  CheckScriptSuccess(lines)
+
+  # Calling the function won't try compiling again
+  assert_fails('call g:Broken()', 'E1091: Function is not compiled: Broken')
+  delfunc g:Broken
 enddef
 
 
index 5cf56feadcdb80a40c29e996270e0a08063958f4..a22312a1518f729540967e4a88505758ad1bd2ac 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2743,
 /**/
     2742,
 /**/
index aa5894a355912dc040b5d61b6540fece1226f2e7..e5e3068d5c9beba25bb603c09b753ed6152efd2f 100644 (file)
@@ -8429,6 +8429,7 @@ compile_def_function(
     cctx_T     cctx;
     garray_T   *instr;
     int                did_emsg_before = did_emsg;
+    int                did_emsg_silent_before = did_emsg_silent;
     int                ret = FAIL;
     sctx_T     save_current_sctx = current_sctx;
     int                save_estack_compiling = estack_compiling;
@@ -8967,6 +8968,9 @@ nextline:
        generate_instr(&cctx, ISN_RETURN_ZERO);
     }
 
+    // When compiled with ":silent!" and there was an error don't consider the
+    // function compiled.
+    if (emsg_silent == 0 || did_emsg_silent == did_emsg_silent_before)
     {
        dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
                                                         + ufunc->uf_dfunc_idx;
@@ -8994,7 +8998,7 @@ nextline:
     ret = OK;
 
 erret:
-    if (ret == FAIL)
+    if (ufunc->uf_def_status == UF_COMPILING)
     {
        int idx;
        dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)