0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch

Problem:    Vim9: a few remaining errors not caught by try/catch.
Solution:   Do not bail out if an error is inside try/catch.
This commit is contained in:
Bram Moolenaar
2020-07-18 18:13:02 +02:00
parent 447bfba24b
commit d032f34a51
3 changed files with 82 additions and 36 deletions

View File

@@ -498,6 +498,10 @@ def Test_cmd_modifier()
call CheckDefFailure(['5tab echo 3'], 'E16:') call CheckDefFailure(['5tab echo 3'], 'E16:')
enddef enddef
func g:NoSuchFunc()
echo 'none'
endfunc
def Test_try_catch() def Test_try_catch()
let l = [] let l = []
try # comment try # comment
@@ -656,6 +660,57 @@ def Test_try_catch()
n = 344 n = 344
endtry endtry
assert_equal(344, n) 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 enddef
def DeletedFunc(): list<any> def DeletedFunc(): list<any>
@@ -2029,7 +2084,7 @@ def Test_vim9_comment()
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'syntax region Word start=/pat/ end=/pat/# comment', 'syntax region Word start=/pat/ end=/pat/# comment',
], 'E475:') ], 'E402:')
CheckScriptSuccess([ CheckScriptSuccess([
'vim9script', 'vim9script',

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1238,
/**/ /**/
1237, 1237,
/**/ /**/

View File

@@ -1512,6 +1512,7 @@ call_def_function(
item->di_tv.v_lock = 0; item->di_tv.v_lock = 0;
if (dict_add(dict, item) == FAIL) if (dict_add(dict, item) == FAIL)
{ {
// can this ever happen?
dict_unref(dict); dict_unref(dict);
goto failed; goto failed;
} }
@@ -1544,7 +1545,7 @@ call_def_function(
if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx, if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx,
iptr->isn_arg.bfunc.cbf_argcount, iptr->isn_arg.bfunc.cbf_argcount,
&ectx) == FAIL) &ectx) == FAIL)
goto failed; goto on_error;
break; break;
// call a funcref or partial // call a funcref or partial
@@ -1571,7 +1572,7 @@ call_def_function(
if (tv == &partial_tv) if (tv == &partial_tv)
clear_tv(&partial_tv); clear_tv(&partial_tv);
if (r == FAIL) if (r == FAIL)
goto failed; goto on_error;
} }
break; break;
@@ -1592,7 +1593,7 @@ call_def_function(
SOURCING_LNUM = iptr->isn_lnum; SOURCING_LNUM = iptr->isn_lnum;
if (call_eval_func(cufunc->cuf_name, if (call_eval_func(cufunc->cuf_name,
cufunc->cuf_argcount, &ectx, iptr) == FAIL) cufunc->cuf_argcount, &ectx, iptr) == FAIL)
goto failed; goto on_error;
} }
break; break;
@@ -1614,19 +1615,7 @@ call_def_function(
trycmd->tcd_return = TRUE; trycmd->tcd_return = TRUE;
} }
else else
{ goto 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)
goto failed;
goto done;
}
if (func_return(&ectx) == FAIL)
goto failed;
}
} }
break; break;
@@ -1735,8 +1724,6 @@ call_def_function(
{ {
listitem_T *li = list_find(list, idxtv->vval.v_number); listitem_T *li = list_find(list, idxtv->vval.v_number);
if (li == NULL)
goto failed;
copy_tv(&li->li_tv, STACK_TV_BOT(0)); copy_tv(&li->li_tv, STACK_TV_BOT(0));
++ectx.ec_stack.ga_len; ++ectx.ec_stack.ga_len;
} }
@@ -1814,19 +1801,7 @@ call_def_function(
} }
if (trycmd->tcd_return) if (trycmd->tcd_return)
{ goto 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)
goto failed;
goto done;
}
if (func_return(&ectx) == FAIL)
goto failed;
}
} }
} }
break; break;
@@ -2068,7 +2043,7 @@ call_def_function(
{ {
n1 = tv_get_number_chk(tv1, &error); n1 = tv_get_number_chk(tv1, &error);
if (error) if (error)
goto failed; goto on_error;
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
if (tv2->v_type == VAR_FLOAT) if (tv2->v_type == VAR_FLOAT)
f1 = n1; f1 = n1;
@@ -2085,7 +2060,7 @@ call_def_function(
{ {
n2 = tv_get_number_chk(tv2, &error); n2 = tv_get_number_chk(tv2, &error);
if (error) if (error)
goto failed; goto on_error;
#ifdef FEAT_FLOAT #ifdef FEAT_FLOAT
if (tv1->v_type == VAR_FLOAT) if (tv1->v_type == VAR_FLOAT)
f2 = n2; f2 = n2;
@@ -2268,7 +2243,7 @@ call_def_function(
if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL) if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
{ {
emsg(_(e_dictreq)); emsg(_(e_dictreq));
goto failed; goto on_error;
} }
dict = tv->vval.v_dict; dict = tv->vval.v_dict;
@@ -2276,7 +2251,7 @@ call_def_function(
== NULL) == NULL)
{ {
semsg(_(e_dictkey), iptr->isn_arg.string); semsg(_(e_dictkey), iptr->isn_arg.string);
goto failed; goto on_error;
} }
// Clear the dict after getting the item, to avoid that it // Clear the dict after getting the item, to avoid that it
// make the item invalid. // make the item invalid.
@@ -2409,6 +2384,20 @@ call_def_function(
} }
continue; 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: on_error:
if (trylevel == 0) if (trylevel == 0)
goto failed; goto failed;