summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-07-17 22:06:44 +0200
committerBram Moolenaar <Bram@vim.org>2020-07-17 22:06:44 +0200
commit68d130c618f363821761f231c4122a0b9b764b71 (patch)
treeef8694372b7cb4299de9f4c89914ada047125a0a
parent6e36b1c18e636549f3424546f2c20101604a2d33 (diff)
downloadvim-git-68d130c618f363821761f231c4122a0b9b764b71.tar.gz
patch 8.2.1230: Vim9: list index error not caught by try/catchv8.2.1230
Problem: Vim9: list index error not caught by try/catch. Solution: Do not bail out if an error is inside try/catch. (closes #6462)
-rw-r--r--src/testdir/test_vim9_script.vim37
-rw-r--r--src/version.c2
-rw-r--r--src/vim9execute.c18
3 files changed, 55 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 24ce668d1..fc2c38046 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -509,6 +509,43 @@ def Test_try_catch()
add(l, '3')
endtry # comment
assert_equal(['1', 'wrong', '3'], l)
+
+ let n: number
+ try
+ n = l[3]
+ catch /E684:/
+ n = 99
+ endtry
+ assert_equal(99, n)
+
+ try
+ n = g:astring[3]
+ catch /E714:/
+ n = 77
+ endtry
+ assert_equal(77, n)
+
+ try
+ n = l[g:astring]
+ catch /E39:/
+ n = 77
+ endtry
+ assert_equal(77, n)
+
+ try
+ n = s:does_not_exist
+ catch /E121:/
+ n = 121
+ endtry
+ assert_equal(121, n)
+
+ let d = #{one: 1}
+ try
+ n = d[g:astring]
+ catch /E716:/
+ n = 222
+ endtry
+ assert_equal(222, n)
enddef
def ThrowFromDef()
diff --git a/src/version.c b/src/version.c
index e43f4e399..7ee429473 100644
--- a/src/version.c
+++ b/src/version.c
@@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1230,
+/**/
1229,
/**/
1228,
diff --git a/src/vim9execute.c b/src/vim9execute.c
index a0d7f630b..fd88986f1 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -1065,6 +1065,8 @@ call_def_function(
if (di == NULL)
{
semsg(_(e_undefvar), name);
+ if (trylevel > 0)
+ continue;
goto failed;
}
else
@@ -1786,6 +1788,7 @@ call_def_function(
--trystack->ga_len;
--trylevel;
+ ectx.ec_in_catch = FALSE;
trycmd = ((trycmd_T *)trystack->ga_data)
+ trystack->ga_len;
if (trycmd->tcd_caught && current_exception != NULL)
@@ -2084,7 +2087,10 @@ call_def_function(
case EXPR_DIV: f1 = f1 / f2; break;
case EXPR_SUB: f1 = f1 - f2; break;
case EXPR_ADD: f1 = f1 + f2; break;
- default: emsg(_(e_modulus)); goto failed;
+ default: emsg(_(e_modulus));
+ if (trylevel > 0)
+ continue;
+ goto failed;
}
clear_tv(tv1);
clear_tv(tv2);
@@ -2138,6 +2144,8 @@ call_def_function(
if (tv->v_type != VAR_LIST)
{
emsg(_(e_listreq));
+ if (trylevel > 0)
+ continue;
goto failed;
}
list = tv->vval.v_list;
@@ -2146,6 +2154,8 @@ call_def_function(
if (tv->v_type != VAR_NUMBER)
{
emsg(_(e_number_exp));
+ if (trylevel > 0)
+ continue;
goto failed;
}
n = tv->vval.v_number;
@@ -2153,11 +2163,13 @@ call_def_function(
if ((li = list_find(list, n)) == NULL)
{
semsg(_(e_listidx), n);
+ if (trylevel > 0)
+ continue;
goto failed;
}
--ectx.ec_stack.ga_len;
// Clear the list after getting the item, to avoid that it
- // make the item invalid.
+ // makes the item invalid.
tv = STACK_TV_BOT(-1);
temp_tv = *tv;
copy_tv(&li->li_tv, tv);
@@ -2226,6 +2238,8 @@ call_def_function(
if ((di = dict_find(dict, key, -1)) == NULL)
{
semsg(_(e_dictkey), key);
+ if (trylevel > 0)
+ continue;
goto failed;
}
clear_tv(tv);