patch 9.1.2111: Vim9: no error for elseif/else after else
Commit:
https://github.com/vim/vim/commit/271a46811e5ccc89000552d3de608556a76bd2a7
Author: Hirohito Higashi <
h.eas...@gmail.com>
Date: Wed Jan 28 19:21:10 2026 +0000
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 <
h.eas...@gmail.com>
Signed-off-by: Yegappan Lakshmanan <
yega...@yahoo.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 8de7bd357..ed946d85d 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 35e3c09a0..de16a77a4 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 be9c67be6..db81229ee 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"