Mercurial > vim
changeset 28299:fae7d94220e3 v8.2.4675
patch 8.2.4675: no error for missing expression after :elseif
Commit: https://github.com/vim/vim/commit/fa010cdfb115fd2f6bae7ea6f6e63be906b5e347
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 3 16:13:07 2022 +0100
patch 8.2.4675: no error for missing expression after :elseif
Problem: No error for missing expression after :elseif. (Ernie Rael)
Solution: Check for missing expression. (closes https://github.com/vim/vim/issues/10068)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 03 Apr 2022 17:15:02 +0200 |
parents | 02ec20ca3576 |
children | 02297ae36206 |
files | src/ex_eval.c src/testdir/test_vim9_script.vim src/version.c |
diffstat | 3 files changed, 18 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ex_eval.c +++ b/src/ex_eval.c @@ -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
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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