1
0
forked from aniani/vim

patch 8.2.2543: Vim9: a return inside try/catch does not restore properly

Problem:    Vim9: a return inside try/catch does not restore exception state
            properly.
Solution:   When there is no ":finally" jump to ":endtry". (closes #7882)
This commit is contained in:
Bram Moolenaar 2021-02-22 22:45:10 +01:00
parent 41f0895c6e
commit 9cb577a682
3 changed files with 20 additions and 4 deletions

View File

@ -589,6 +589,18 @@ def Test_try_catch_throw()
assert_equal(4, ReturnInFinally()) assert_equal(4, ReturnInFinally())
enddef enddef
def Test_nocatch_return_in_try()
# return in try block returns normally
def ReturnInTry(): string
try
return '"some message"'
catch
endtry
return 'not reached'
enddef
exe 'echoerr ' .. ReturnInTry()
enddef
def Test_cnext_works_in_catch() def Test_cnext_works_in_catch()
var lines =<< trim END var lines =<< trim END
vim9script vim9script

View File

@ -750,6 +750,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 */
/**/
2543,
/**/ /**/
2542, 2542,
/**/ /**/

View File

@ -2517,11 +2517,13 @@ call_def_function(
trycmd = ((trycmd_T *)trystack->ga_data) trycmd = ((trycmd_T *)trystack->ga_data)
+ trystack->ga_len - 1; + trystack->ga_len - 1;
if (trycmd != NULL if (trycmd != NULL
&& trycmd->tcd_frame_idx == ectx.ec_frame_idx && trycmd->tcd_frame_idx == ectx.ec_frame_idx)
&& trycmd->tcd_finally_idx != 0)
{ {
// jump to ":finally" once // jump to ":finally" or ":endtry"
ectx.ec_iidx = trycmd->tcd_finally_idx; if (trycmd->tcd_finally_idx != 0)
ectx.ec_iidx = trycmd->tcd_finally_idx;
else
ectx.ec_iidx = trycmd->tcd_endtry_idx;
trycmd->tcd_return = TRUE; trycmd->tcd_return = TRUE;
} }
else else