From: Hirohito Higashi Date: Wed, 28 Jan 2026 19:21:10 +0000 (+0000) Subject: patch 9.1.2111: Vim9: no error for elseif/else after else X-Git-Tag: v9.1.2111^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=271a46811e5ccc89000552d3de608556a76bd2a7;p=thirdparty%2Fvim.git patch 9.1.2111: Vim9: no error for elseif/else after else Problem: Vim9: no error for elseif/else after else Solution: Report an error (Hirohito Higashi) closes: #19263 Signed-off-by: Hirohito Higashi Signed-off-by: Yegappan Lakshmanan Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 8de7bd3579..ed946d85db 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1995,6 +1995,25 @@ def Test_if_elseif_else_fails() END v9.CheckDefFailure(lines, 'E488:') + + lines =<< trim END + if true + else + else + endif + END + v9.CheckSourceDefFailure(lines, 'E583:') + + lines =<< trim END + var a = 3 + if a == 2 + else + elseif true + else + endif + END + v9.CheckSourceDefFailure(lines, 'E584:') + lines =<< trim END var cond = true if cond diff --git a/src/version.c b/src/version.c index 35e3c09a02..de16a77a48 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2111, /**/ 2110, /**/ diff --git a/src/vim9cmds.c b/src/vim9cmds.c index be9c67be69..db81229eed 100644 --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -596,6 +596,11 @@ compile_elseif(char_u *arg, cctx_T *cctx) emsg(_(e_elseif_without_if)); return NULL; } + if (scope->se_u.se_if.is_seen_else) + { + emsg(_(e_elseif_after_else)); + return NULL; + } unwind_locals(cctx, scope->se_local_count, TRUE); if (!cctx->ctx_had_return && !cctx->ctx_had_throw) // the previous if block didn't end in a "return" or a "throw" @@ -745,6 +750,11 @@ compile_else(char_u *arg, cctx_T *cctx) emsg(_(e_else_without_if)); return NULL; } + if (scope->se_u.se_if.is_seen_else) + { + emsg(_(e_multiple_else)); + return NULL; + } unwind_locals(cctx, scope->se_local_count, TRUE); if (!cctx->ctx_had_return && !cctx->ctx_had_throw) // the previous if block didn't end in a "return" or a "throw"