0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.1.1593: Confusing error when compiling incomplete try block

Problem:  Confusing error when compiling incomplete try block
          (lacygoill)
Solution: Give better error messages (Hirohito Higashi)

fixes: #17833
closes: #17853

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Hirohito Higashi
2025-08-05 20:03:36 +02:00
committed by Christian Brabandt
parent becf1844e0
commit 27b61f20b7
3 changed files with 53 additions and 9 deletions

View File

@@ -1426,6 +1426,31 @@ def Test_try_catch_fails()
v9.CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:') v9.CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:')
v9.CheckDefFailure(['if 1', 'endtry'], 'E171:') v9.CheckDefFailure(['if 1', 'endtry'], 'E171:')
v9.CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:') v9.CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
v9.CheckDefFailure(['try'], 'E600:')
v9.CheckDefFailure(['try', 'echo 0'], 'E600:')
v9.CheckDefFailure(['try', 'echo 0', 'catch'], 'E600:')
v9.CheckDefFailure(['try', 'echo 0', 'catch', 'echo 1'], 'E600:')
v9.CheckDefFailure(['try', 'echo 0', 'catch', 'echo 1', 'finally'], 'E600:')
v9.CheckDefFailure(['try', 'echo 0', 'catch', 'echo 1', 'finally', 'echo 2'], 'E600:')
# Missing :endtry inside a nested :try
var outer1 =<< trim END
try
echo 0
catch
echo 1
END
var outer2 =<< trim END
finally
echo 2
endtry
END
v9.CheckDefFailure(outer1 + ['try'] + outer2, 'E600:')
v9.CheckDefFailure(outer1 + ['try', 'echo 10'] + outer2, 'E600:')
v9.CheckDefFailure(outer1 + ['try', 'echo 10', 'catch'] + outer2, 'E600:')
v9.CheckDefFailure(outer1 + ['try', 'echo 10', 'catch', 'echo 11'] + outer2, 'E600:')
v9.CheckDefFailure(outer1 + ['try', 'echo 10', 'catch', 'echo 11', 'finally'] + outer2, 'E607:')
v9.CheckDefFailure(outer1 + ['try', 'echo 10', 'catch', 'echo 11', 'finally', 'echo 12'] + outer2, 'E607:')
v9.CheckDefFailure(['throw'], 'E1143:') v9.CheckDefFailure(['throw'], 'E1143:')
v9.CheckDefFailure(['throw xxx'], 'E1001:') v9.CheckDefFailure(['throw xxx'], 'E1001:')

View File

@@ -719,6 +719,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 */
/**/
1593,
/**/ /**/
1592, 1592,
/**/ /**/

View File

@@ -4800,15 +4800,32 @@ compile_dfunc_scope_end_missing(cctx_T *cctx)
if (cctx->ctx_scope == NULL) if (cctx->ctx_scope == NULL)
return FALSE; return FALSE;
if (cctx->ctx_scope->se_type == IF_SCOPE) switch (cctx->ctx_scope->se_type)
emsg(_(e_missing_endif)); {
else if (cctx->ctx_scope->se_type == WHILE_SCOPE) case IF_SCOPE:
emsg(_(e_missing_endwhile)); emsg(_(e_missing_endif));
else if (cctx->ctx_scope->se_type == FOR_SCOPE) break;
emsg(_(e_missing_endfor)); case WHILE_SCOPE:
else emsg(_(e_missing_endwhile));
emsg(_(e_missing_rcurly)); break;
case FOR_SCOPE:
emsg(_(e_missing_endfor));
break;
case TRY_SCOPE:
emsg(_(e_missing_endtry));
break;
case BLOCK_SCOPE:
// end block scope from :try (maybe)
compile_endblock(cctx);
if (cctx->ctx_scope != NULL
&& cctx->ctx_scope->se_type == TRY_SCOPE)
emsg(_(e_missing_endtry));
else
emsg(_(e_missing_rcurly));
break;
default:
emsg(_(e_missing_rcurly));
}
return TRUE; return TRUE;
} }