mirror of
https://github.com/vim/vim.git
synced 2025-09-27 04:14:06 -04:00
patch 8.2.3099: Vim9: missing catch/finally not reported at script level
Problem: Vim9: missing catch/finally not reported at script level. Solution: Give an error. (closes #8487)
This commit is contained in:
@@ -1670,6 +1670,8 @@ ex_catch(exarg_T *eap)
|
|||||||
for (idx = cstack->cs_idx; idx > 0; --idx)
|
for (idx = cstack->cs_idx; idx > 0; --idx)
|
||||||
if (cstack->cs_flags[idx] & CSF_TRY)
|
if (cstack->cs_flags[idx] & CSF_TRY)
|
||||||
break;
|
break;
|
||||||
|
if (cstack->cs_flags[idx] & CSF_TRY)
|
||||||
|
cstack->cs_flags[idx] |= CSF_CATCH;
|
||||||
if (cstack->cs_flags[idx] & CSF_FINALLY)
|
if (cstack->cs_flags[idx] & CSF_FINALLY)
|
||||||
{
|
{
|
||||||
// Give up for a ":catch" after ":finally" and ignore it.
|
// Give up for a ":catch" after ":finally" and ignore it.
|
||||||
@@ -1963,8 +1965,8 @@ ex_endtry(exarg_T *eap)
|
|||||||
* made inactive by a ":continue", ":break", ":return", or ":finish" in
|
* made inactive by a ":continue", ":break", ":return", or ":finish" in
|
||||||
* the finally clause. The latter case need not be tested since then
|
* the finally clause. The latter case need not be tested since then
|
||||||
* anything pending has already been discarded. */
|
* anything pending has already been discarded. */
|
||||||
skip = did_emsg || got_int || did_throw ||
|
skip = did_emsg || got_int || did_throw
|
||||||
!(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
|
|| !(cstack->cs_flags[cstack->cs_idx] & CSF_TRUE);
|
||||||
|
|
||||||
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
|
if (!(cstack->cs_flags[cstack->cs_idx] & CSF_TRY))
|
||||||
{
|
{
|
||||||
@@ -1992,6 +1994,14 @@ ex_endtry(exarg_T *eap)
|
|||||||
{
|
{
|
||||||
idx = cstack->cs_idx;
|
idx = cstack->cs_idx;
|
||||||
|
|
||||||
|
if (in_vim9script()
|
||||||
|
&& (cstack->cs_flags[idx] & (CSF_CATCH|CSF_FINALLY)) == 0)
|
||||||
|
{
|
||||||
|
// try/endtry without any catch or finally: give an error and
|
||||||
|
// continue.
|
||||||
|
eap->errmsg = _(e_missing_catch_or_finally);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we stopped with the exception currently being thrown at this
|
* If we stopped with the exception currently being thrown at this
|
||||||
* try conditional since we didn't know that it doesn't have
|
* try conditional since we didn't know that it doesn't have
|
||||||
|
@@ -936,13 +936,14 @@ typedef struct {
|
|||||||
|
|
||||||
# define CSF_TRY 0x0100 // is a ":try"
|
# define CSF_TRY 0x0100 // is a ":try"
|
||||||
# define CSF_FINALLY 0x0200 // ":finally" has been passed
|
# define CSF_FINALLY 0x0200 // ":finally" has been passed
|
||||||
# define CSF_THROWN 0x0400 // exception thrown to this try conditional
|
# define CSF_CATCH 0x0400 // ":catch" has been seen
|
||||||
# define CSF_CAUGHT 0x0800 // exception caught by this try conditional
|
# define CSF_THROWN 0x0800 // exception thrown to this try conditional
|
||||||
# define CSF_SILENT 0x1000 // "emsg_silent" reset by ":try"
|
# define CSF_CAUGHT 0x1000 // exception caught by this try conditional
|
||||||
|
# define CSF_SILENT 0x2000 // "emsg_silent" reset by ":try"
|
||||||
// Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset
|
// Note that CSF_ELSE is only used when CSF_TRY and CSF_WHILE are unset
|
||||||
// (an ":if"), and CSF_SILENT is only used when CSF_TRY is set.
|
// (an ":if"), and CSF_SILENT is only used when CSF_TRY is set.
|
||||||
//
|
//
|
||||||
#define CSF_FUNC_DEF 0x2000 // a function was defined in this block
|
#define CSF_FUNC_DEF 0x4000 // a function was defined in this block
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* What's pending for being reactivated at the ":endtry" of this try
|
* What's pending for being reactivated at the ":endtry" of this try
|
||||||
|
@@ -603,6 +603,15 @@ def Test_try_catch_throw()
|
|||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
assert_match('E808: Number or Float required', g:caught)
|
assert_match('E808: Number or Float required', g:caught)
|
||||||
unlet g:caught
|
unlet g:caught
|
||||||
|
|
||||||
|
# missing catch and/or finally
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
try
|
||||||
|
echo 'something'
|
||||||
|
endtry
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1032:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_try_in_catch()
|
def Test_try_in_catch()
|
||||||
|
@@ -755,6 +755,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 */
|
||||||
|
/**/
|
||||||
|
3099,
|
||||||
/**/
|
/**/
|
||||||
3098,
|
3098,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user