]> granicus.if.org Git - vim/commitdiff
patch 8.2.4675: no error for missing expression after :elseif v8.2.4675
authorBram Moolenaar <Bram@vim.org>
Sun, 3 Apr 2022 15:13:07 +0000 (16:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 3 Apr 2022 15:13:07 +0000 (16:13 +0100)
Problem:    No error for missing expression after :elseif. (Ernie Rael)
Solution:   Check for missing expression. (closes #10068)

src/ex_eval.c
src/testdir/test_vim9_script.vim
src/version.c

index e3c544b892ab72ae6dd775dbe8ff99631ed9accd..9a2792a2ac01f2f044f61bdf85a931b23aec6822 100644 (file)
@@ -1146,7 +1146,12 @@ ex_else(exarg_T *eap)
 
     if (eap->cmdidx == CMD_elseif)
     {
-       result = eval_to_bool(eap->arg, &error, eap, skip);
+       // When skipping we ignore most errors, but a missing expression is
+       // wrong, perhaps it should have been "else".
+       if (skip && ends_excmd(*eap->arg))
+           semsg(_(e_invalid_expression_str), eap->arg);
+       else
+           result = eval_to_bool(eap->arg, &error, eap, skip);
 
        // When throwing error exceptions, we want to throw always the first
        // of several errors in a row.  This is what actually happens when
index 54864587fe87884fc650a5819008e71ba90664d2..56842b326815e5cbf39583fd03520f2f0a78798b 100644 (file)
@@ -1605,6 +1605,16 @@ def Test_if_elseif_else_fails()
       endif
   END
   v9.CheckDefFailure(lines, 'E488:')
+
+  lines =<< trim END
+      var cond = true
+      if cond
+        echo 'true'
+      elseif
+        echo 'false'
+      endif
+  END
+  v9.CheckDefAndScriptFailure(lines, ['E1143:', 'E15:'], 4)
 enddef
 
 let g:bool_true = v:true
index 602366f62f5cdd9b2d089d91e13f4200f5601690..ec9be2896610e0caa2ed5c176956dfaccdb14885 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4675,
 /**/
     4674,
 /**/