]> granicus.if.org Git - vim/commitdiff
patch 8.2.2351: Vim9: error msg for "throw" in function called with "silent!" v8.2.2351
authorBram Moolenaar <Bram@vim.org>
Thu, 14 Jan 2021 20:47:06 +0000 (21:47 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 14 Jan 2021 20:47:06 +0000 (21:47 +0100)
Problem:    Vim9: error message for "throw" in function that was called with
            "silent!".
Solution:   Do not throw the exception when not caught or displayed.
            (closes #7672)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9execute.c

index d567de75f815518d9e214a156edbcd0f373b5eff..158c64c27c091f08780f95a7045b0810f7613f9f 100644 (file)
@@ -564,6 +564,19 @@ def Test_throw_skipped()
   endif
 enddef
 
+def Test_nocatch_throw_silenced()
+  var lines =<< trim END
+    vim9script
+    def Func()
+      throw 'error'
+    enddef
+    silent! Func()
+  END
+  writefile(lines, 'XthrowSilenced')
+  source XthrowSilenced
+  delete('XthrowSilenced')
+enddef
+
 def DeletedFunc(): list<any>
   return ['delete me']
 enddef
index 616f4ede8509df5cab57561869ca4960e69c367d..b2de0115a2d12137fc79bb73111f91af7a59781d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2351,
 /**/
     2350,
 /**/
index 938fc2e191e8c6fd857160c6ab910912cdb0eef2..9c9c273650176e33bf4234d959b0b8ec8443311f 100644 (file)
@@ -2605,6 +2605,17 @@ call_def_function(
                break;
 
            case ISN_THROW:
+               if (ectx.ec_trystack.ga_len == 0 && trylevel == 0
+                                                               && emsg_silent)
+               {
+                   // throwing an exception while using "silent!" causes the
+                   // function to abort but not display an error.
+                   tv = STACK_TV_BOT(-1);
+                   clear_tv(tv);
+                   tv->v_type = VAR_NUMBER;
+                   tv->vval.v_number = 0;
+                   goto done;
+               }
                --ectx.ec_stack.ga_len;
                tv = STACK_TV_BOT(0);
                if (tv->vval.v_string == NULL