Skip to content
Snippets Groups Projects
Commit f0b9f43c authored by Bram Moolenaar's avatar Bram Moolenaar
Browse files

patch 8.2.1233: Vim9: various errors not caught by try/catch

Problem:    Vim9: various errors not caught by try/catch.
Solution:   Do not bail out if an error is inside try/catch.
parent b68ced5f
No related branches found
Tags v8.2.1233
No related merge requests found
......@@ -17,6 +17,7 @@ let g:inc_counter = 1
let $SOME_ENV_VAR = 'some'
let g:alist = [7]
let g:astring = 'text'
let g:anumber = 123
def Test_assignment()
let bool1: bool = true
......@@ -534,6 +535,13 @@ def Test_try_catch()
try
n = s:does_not_exist
catch /E121:/
n = 111
endtry
assert_equal(111, n)
try
n = g:does_not_exist
catch /E121:/
n = 121
endtry
......@@ -546,6 +554,50 @@ def Test_try_catch()
n = 222
endtry
assert_equal(222, n)
try
n = -g:astring
catch /E39:/
n = 233
endtry
assert_equal(233, n)
try
n = +g:astring
catch /E1030:/
n = 244
endtry
assert_equal(244, n)
try
n = +g:alist
catch /E745:/
n = 255
endtry
assert_equal(255, n)
let nd: dict<any>
try
nd = {g:anumber: 1}
catch /E1029:/
n = 266
endtry
assert_equal(266, n)
try
[n] = [1, 2, 3]
catch /E1093:/
n = 277
endtry
assert_equal(277, n)
# TODO: make this work
# try
# &ts = g:astring
# catch /E1093:/
# n = 288
# endtry
# assert_equal(288, n)
enddef
def ThrowFromDef()
......
......@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1233,
/**/
1232,
/**/
......
......@@ -1065,9 +1065,7 @@ call_def_function(
if (di == NULL)
{
semsg(_(e_undefvar), name);
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
else
{
......@@ -1115,7 +1113,7 @@ call_def_function(
{
semsg(_("E121: Undefined variable: %c:%s"),
namespace, iptr->isn_arg.string);
goto failed;
goto on_error;
}
else
{
......@@ -2088,9 +2086,7 @@ call_def_function(
case EXPR_SUB: f1 = f1 - f2; break;
case EXPR_ADD: f1 = f1 + f2; break;
default: emsg(_(e_modulus));
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
clear_tv(tv1);
clear_tv(tv2);
......@@ -2144,9 +2140,7 @@ call_def_function(
if (tv->v_type != VAR_LIST)
{
emsg(_(e_listreq));
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
list = tv->vval.v_list;
......@@ -2154,18 +2148,14 @@ call_def_function(
if (tv->v_type != VAR_NUMBER)
{
emsg(_(e_number_exp));
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
n = tv->vval.v_number;
clear_tv(tv);
if ((li = list_find(list, n)) == NULL)
{
semsg(_(e_listidx), n);
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
--ectx.ec_stack.ga_len;
// Clear the list after getting the item, to avoid that it
......@@ -2238,9 +2228,7 @@ call_def_function(
if ((di = dict_find(dict, key, -1)) == NULL)
{
semsg(_(e_dictkey), key);
if (trylevel > 0)
continue;
goto failed;
goto on_error;
}
clear_tv(tv);
--ectx.ec_stack.ga_len;
......@@ -2291,7 +2279,7 @@ call_def_function(
)
{
emsg(_(e_number_exp));
goto failed;
goto on_error;
}
#ifdef FEAT_FLOAT
if (tv->v_type == VAR_FLOAT)
......@@ -2307,10 +2295,10 @@ call_def_function(
tv = STACK_TV_BOT(-1);
if (check_not_string(tv) == FAIL)
goto failed;
goto on_error;
(void)tv_get_number_chk(tv, &error);
if (error)
goto failed;
goto on_error;
}
break;
......@@ -2329,7 +2317,7 @@ call_def_function(
semsg(_("E1029: Expected %s but got %s"),
vartype_name(ct->ct_type),
vartype_name(tv->v_type));
goto failed;
goto on_error;
}
}
break;
......@@ -2348,7 +2336,7 @@ call_def_function(
{
semsg(_("E1093: Expected %d items but got %d"),
min_len, list == NULL ? 0 : list->lv_len);
goto failed;
goto on_error;
}
}
break;
......@@ -2403,6 +2391,11 @@ call_def_function(
clear_tv(STACK_TV_BOT(0));
break;
}
continue;
on_error:
if (trylevel == 0)
goto failed;
}
done:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment