]> granicus.if.org Git - vim/commitdiff
patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch v8.2.1238
authorBram Moolenaar <Bram@vim.org>
Sat, 18 Jul 2020 16:13:02 +0000 (18:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 18 Jul 2020 16:13:02 +0000 (18:13 +0200)
Problem:    Vim9: a few remaining errors not caught by try/catch.
Solution:   Do not bail out if an error is inside try/catch.

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

index a646de9785fc2bb8367dddb2f4cba60f87c0f8e2..035c731cc48365fd036534983b62288dab4fceb8 100644 (file)
@@ -498,6 +498,10 @@ def Test_cmd_modifier()
   call CheckDefFailure(['5tab echo 3'], 'E16:')
 enddef
 
+func g:NoSuchFunc()
+  echo 'none'
+endfunc
+
 def Test_try_catch()
   let l = []
   try # comment
@@ -656,6 +660,57 @@ def Test_try_catch()
     n = 344
   endtry
   assert_equal(344, n)
+
+  try
+    echo len(v:true)
+  catch /E701:/
+    n = 355
+  endtry
+  assert_equal(355, n)
+
+  let P = function('g:NoSuchFunc')
+  delfunc g:NoSuchFunc
+  try
+    echo P()
+  catch /E117:/
+    n = 366
+  endtry
+  assert_equal(366, n)
+
+  try
+    echo g:NoSuchFunc()
+  catch /E117:/
+    n = 377
+  endtry
+  assert_equal(377, n)
+
+  try
+    echo g:alist + 4
+  catch /E745:/
+    n = 388
+  endtry
+  assert_equal(388, n)
+
+  try
+    echo 4 + g:alist
+  catch /E745:/
+    n = 399
+  endtry
+  assert_equal(399, n)
+
+  try
+    echo g:alist.member
+  catch /E715:/
+    n = 400
+  endtry
+  assert_equal(400, n)
+
+  try
+    echo d.member
+  catch /E716:/
+    n = 411
+  endtry
+  assert_equal(411, n)
 enddef
 
 def DeletedFunc(): list<any>
@@ -2029,7 +2084,7 @@ def Test_vim9_comment()
   CheckScriptFailure([
       'vim9script',
       'syntax region Word start=/pat/ end=/pat/# comment',
-      ], 'E475:')
+      ], 'E402:')
 
   CheckScriptSuccess([
       'vim9script',
index 06f7fd2b85ad8adee7639b96c5226bbdffe1a2e6..77576d9a930e90c9d4995695b78e429728694569 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1238,
 /**/
     1237,
 /**/
index ce127816702ebf270bc792e9574f09e0608863a0..9f037a3be14d1984471596665ae4e34fd0ca9c36 100644 (file)
@@ -1512,6 +1512,7 @@ call_def_function(
                        item->di_tv.v_lock = 0;
                        if (dict_add(dict, item) == FAIL)
                        {
+                           // can this ever happen?
                            dict_unref(dict);
                            goto failed;
                        }
@@ -1544,7 +1545,7 @@ call_def_function(
                if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx,
                              iptr->isn_arg.bfunc.cbf_argcount,
                              &ectx) == FAIL)
-                   goto failed;
+                   goto on_error;
                break;
 
            // call a funcref or partial
@@ -1571,7 +1572,7 @@ call_def_function(
                    if (tv == &partial_tv)
                        clear_tv(&partial_tv);
                    if (r == FAIL)
-                       goto failed;
+                       goto on_error;
                }
                break;
 
@@ -1592,7 +1593,7 @@ call_def_function(
                    SOURCING_LNUM = iptr->isn_lnum;
                    if (call_eval_func(cufunc->cuf_name,
                                    cufunc->cuf_argcount, &ectx, iptr) == FAIL)
-                       goto failed;
+                       goto on_error;
                }
                break;
 
@@ -1614,19 +1615,7 @@ call_def_function(
                        trycmd->tcd_return = TRUE;
                    }
                    else
-                   {
-                       // Restore previous function. If the frame pointer
-                       // is zero then there is none and we are done.
-                       if (ectx.ec_frame_idx == initial_frame_idx)
-                       {
-                           if (handle_closure_in_use(&ectx, FALSE) == FAIL)
-                               goto failed;
-                           goto done;
-                       }
-
-                       if (func_return(&ectx) == FAIL)
-                           goto failed;
-                   }
+                       goto func_return;
                }
                break;
 
@@ -1735,8 +1724,6 @@ call_def_function(
                    {
                        listitem_T *li = list_find(list, idxtv->vval.v_number);
 
-                       if (li == NULL)
-                           goto failed;
                        copy_tv(&li->li_tv, STACK_TV_BOT(0));
                        ++ectx.ec_stack.ga_len;
                    }
@@ -1814,19 +1801,7 @@ call_def_function(
                        }
 
                        if (trycmd->tcd_return)
-                       {
-                           // Restore previous function. If the frame pointer
-                           // is zero then there is none and we are done.
-                           if (ectx.ec_frame_idx == initial_frame_idx)
-                           {
-                               if (handle_closure_in_use(&ectx, FALSE) == FAIL)
-                                   goto failed;
-                               goto done;
-                           }
-
-                           if (func_return(&ectx) == FAIL)
-                               goto failed;
-                       }
+                           goto func_return;
                    }
                }
                break;
@@ -2068,7 +2043,7 @@ call_def_function(
                    {
                        n1 = tv_get_number_chk(tv1, &error);
                        if (error)
-                           goto failed;
+                           goto on_error;
 #ifdef FEAT_FLOAT
                        if (tv2->v_type == VAR_FLOAT)
                            f1 = n1;
@@ -2085,7 +2060,7 @@ call_def_function(
                    {
                        n2 = tv_get_number_chk(tv2, &error);
                        if (error)
-                           goto failed;
+                           goto on_error;
 #ifdef FEAT_FLOAT
                        if (tv1->v_type == VAR_FLOAT)
                            f2 = n2;
@@ -2268,7 +2243,7 @@ call_def_function(
                    if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
                    {
                        emsg(_(e_dictreq));
-                       goto failed;
+                       goto on_error;
                    }
                    dict = tv->vval.v_dict;
 
@@ -2276,7 +2251,7 @@ call_def_function(
                                                                       == NULL)
                    {
                        semsg(_(e_dictkey), iptr->isn_arg.string);
-                       goto failed;
+                       goto on_error;
                    }
                    // Clear the dict after getting the item, to avoid that it
                    // make the item invalid.
@@ -2409,6 +2384,20 @@ call_def_function(
        }
        continue;
 
+func_return:
+       // Restore previous function. If the frame pointer is zero then there
+       // is none and we are done.
+       if (ectx.ec_frame_idx == initial_frame_idx)
+       {
+           if (handle_closure_in_use(&ectx, FALSE) == FAIL)
+               // only fails when out of memory
+               goto failed;
+           goto done;
+       }
+       if (func_return(&ectx) == FAIL)
+           // only fails when out of memory
+           goto failed;
+
 on_error:
        if (trylevel == 0)
            goto failed;