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

patch 8.2.4071: Vim9: no detection of return in try/endtry

Problem:    Vim9: no detection of return in try/endtry. (Dominique Pellé)
Solution:   Check if any of the blocks inside try/endtry did not end in
            return.
This commit is contained in:
Bram Moolenaar
2022-01-12 16:18:18 +00:00
parent f5d639a8af
commit 53c296112e
5 changed files with 73 additions and 2 deletions

View File

@@ -1343,6 +1343,8 @@ compile_catch(char_u *arg, cctx_T *cctx UNUSED)
emsg(_(e_catch_unreachable_after_catch_all));
return NULL;
}
if (!cctx->ctx_had_return)
scope->se_u.se_try.ts_no_return = TRUE;
if (cctx->ctx_skip != SKIP_YES)
{
@@ -1498,6 +1500,7 @@ compile_finally(char_u *arg, cctx_T *cctx)
isn->isn_arg.jump.jump_where = this_instr;
scope->se_u.se_try.ts_catch_label = 0;
}
scope->se_u.se_try.ts_has_finally = TRUE;
if (generate_instr(cctx, ISN_FINALLY) == NULL)
return NULL;
}
@@ -1567,6 +1570,14 @@ compile_endtry(char_u *arg, cctx_T *cctx)
}
}
// If there is a finally clause that ends in return then we will return.
// If one of the blocks didn't end in "return" or we did not catch all
// exceptions reset the had_return flag.
if (!(scope->se_u.se_try.ts_has_finally && cctx->ctx_had_return)
&& (scope->se_u.se_try.ts_no_return
|| !scope->se_u.se_try.ts_caught_all))
cctx->ctx_had_return = FALSE;
compile_endblock(cctx);
if (cctx->ctx_skip != SKIP_YES)