]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2111: Vim9: no error for elseif/else after else v9.1.2111
authorHirohito Higashi <h.east.727@gmail.com>
Wed, 28 Jan 2026 19:21:10 +0000 (19:21 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 28 Jan 2026 19:21:10 +0000 (19:21 +0000)
Problem:  Vim9: no error for elseif/else after else
Solution: Report an error (Hirohito Higashi)

closes: #19263

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_script.vim
src/version.c
src/vim9cmds.c

index 8de7bd3579a15fa946665028f5831aa3e224f950..ed946d85db638fd05c7ac3179bc75c10bd8d9d0e 100644 (file)
@@ -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
index 35e3c09a0238c7735045562c2911db11a4a378dc..de16a77a482f4c0b623976eed8d4e623d8a1a6a2 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2111,
 /**/
     2110,
 /**/
index be9c67be691ab134b077a4296059e8b59d2a46ae..db81229eed0e1555445a5e1af61224f7f0c6c830 100644 (file)
@@ -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"