To: vim_dev@googlegroups.com Subject: Patch 8.2.1238 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1238 Problem: Vim9: a few remaining errors not caught by try/catch. Solution: Do not bail out if an error is inside try/catch. Files: src/vim9execute.c, src/testdir/test_vim9_script.vim *** ../vim-8.2.1237/src/vim9execute.c 2020-07-18 15:16:58.307407071 +0200 --- src/vim9execute.c 2020-07-18 18:11:49.734933700 +0200 *************** *** 1512,1517 **** --- 1512,1518 ---- item->di_tv.v_lock = 0; if (dict_add(dict, item) == FAIL) { + // can this ever happen? dict_unref(dict); goto failed; } *************** *** 1544,1550 **** if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx, iptr->isn_arg.bfunc.cbf_argcount, &ectx) == FAIL) ! goto failed; break; // call a funcref or partial --- 1545,1551 ---- if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx, iptr->isn_arg.bfunc.cbf_argcount, &ectx) == FAIL) ! goto on_error; break; // call a funcref or partial *************** *** 1571,1577 **** if (tv == &partial_tv) clear_tv(&partial_tv); if (r == FAIL) ! goto failed; } break; --- 1572,1578 ---- if (tv == &partial_tv) clear_tv(&partial_tv); if (r == FAIL) ! goto on_error; } break; *************** *** 1592,1598 **** SOURCING_LNUM = iptr->isn_lnum; if (call_eval_func(cufunc->cuf_name, cufunc->cuf_argcount, &ectx, iptr) == FAIL) ! goto failed; } break; --- 1593,1599 ---- SOURCING_LNUM = iptr->isn_lnum; if (call_eval_func(cufunc->cuf_name, cufunc->cuf_argcount, &ectx, iptr) == FAIL) ! goto on_error; } break; *************** *** 1614,1632 **** 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; ! } } break; --- 1615,1621 ---- trycmd->tcd_return = TRUE; } else ! goto func_return; } break; *************** *** 1735,1742 **** { 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; } --- 1724,1729 ---- *************** *** 1814,1832 **** } 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; ! } } } break; --- 1801,1807 ---- } if (trycmd->tcd_return) ! goto func_return; } } break; *************** *** 2068,2074 **** { n1 = tv_get_number_chk(tv1, &error); if (error) ! goto failed; #ifdef FEAT_FLOAT if (tv2->v_type == VAR_FLOAT) f1 = n1; --- 2043,2049 ---- { n1 = tv_get_number_chk(tv1, &error); if (error) ! goto on_error; #ifdef FEAT_FLOAT if (tv2->v_type == VAR_FLOAT) f1 = n1; *************** *** 2085,2091 **** { n2 = tv_get_number_chk(tv2, &error); if (error) ! goto failed; #ifdef FEAT_FLOAT if (tv1->v_type == VAR_FLOAT) f2 = n2; --- 2060,2066 ---- { n2 = tv_get_number_chk(tv2, &error); if (error) ! goto on_error; #ifdef FEAT_FLOAT if (tv1->v_type == VAR_FLOAT) f2 = n2; *************** *** 2268,2274 **** if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL) { emsg(_(e_dictreq)); ! goto failed; } dict = tv->vval.v_dict; --- 2243,2249 ---- if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL) { emsg(_(e_dictreq)); ! goto on_error; } dict = tv->vval.v_dict; *************** *** 2276,2282 **** == NULL) { semsg(_(e_dictkey), iptr->isn_arg.string); ! goto failed; } // Clear the dict after getting the item, to avoid that it // make the item invalid. --- 2251,2257 ---- == NULL) { semsg(_(e_dictkey), iptr->isn_arg.string); ! goto on_error; } // Clear the dict after getting the item, to avoid that it // make the item invalid. *************** *** 2409,2414 **** --- 2384,2403 ---- } 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; *** ../vim-8.2.1237/src/testdir/test_vim9_script.vim 2020-07-18 15:16:58.307407071 +0200 --- src/testdir/test_vim9_script.vim 2020-07-18 18:10:13.171241181 +0200 *************** *** 498,503 **** --- 498,507 ---- call CheckDefFailure(['5tab echo 3'], 'E16:') enddef + func g:NoSuchFunc() + echo 'none' + endfunc + def Test_try_catch() let l = [] try # comment *************** *** 656,661 **** --- 660,716 ---- 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 *************** *** 2029,2035 **** CheckScriptFailure([ 'vim9script', 'syntax region Word start=/pat/ end=/pat/# comment', ! ], 'E475:') CheckScriptSuccess([ 'vim9script', --- 2084,2090 ---- CheckScriptFailure([ 'vim9script', 'syntax region Word start=/pat/ end=/pat/# comment', ! ], 'E402:') CheckScriptSuccess([ 'vim9script', *** ../vim-8.2.1237/src/version.c 2020-07-18 16:07:02.009864381 +0200 --- src/version.c 2020-07-18 18:12:18.034843725 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1238, /**/ -- A day without sunshine is like, well, night. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///