patch 9.1.1593: Confusing error when compiling incomplete try block Commit: https://github.com/vim/vim/commit/27b61f20b7ec7ae4eeb6e23e0dee4039370e2484 Author: Hirohito Higashi <h.east....@gmail.com> Date: Tue Aug 5 20:03:36 2025 +0200
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....@gmail.com> Signed-off-by: Christian Brabandt <c...@256bit.org> diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 8e968d6ef..76fc36eb1 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1426,6 +1426,31 @@ def Test_try_catch_fails() v9.CheckDefFailure(['for i in range(5)', 'endtry'], 'E170:') v9.CheckDefFailure(['if 1', 'endtry'], 'E171:') 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 xxx'], 'E1001:') diff --git a/src/version.c b/src/version.c index fecf9219f..ea483004f 100644 --- a/src/version.c +++ b/src/version.c @@ -719,6 +719,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1593, /**/ 1592, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index f9998ceff..65e0ff194 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -4800,15 +4800,32 @@ compile_dfunc_scope_end_missing(cctx_T *cctx) if (cctx->ctx_scope == NULL) return FALSE; - if (cctx->ctx_scope->se_type == IF_SCOPE) - emsg(_(e_missing_endif)); - else if (cctx->ctx_scope->se_type == WHILE_SCOPE) - emsg(_(e_missing_endwhile)); - else if (cctx->ctx_scope->se_type == FOR_SCOPE) - emsg(_(e_missing_endfor)); - else - emsg(_(e_missing_rcurly)); - + switch (cctx->ctx_scope->se_type) + { + case IF_SCOPE: + emsg(_(e_missing_endif)); + break; + case WHILE_SCOPE: + emsg(_(e_missing_endwhile)); + 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; } -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/vim_dev/E1ujMBj-00EP9T-KT%40256bit.org.