diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-04-03 16:13:07 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-04-03 16:13:07 +0100 |
commit | fa010cdfb115fd2f6bae7ea6f6e63be906b5e347 (patch) | |
tree | aba04c965c48050cb54ce0328d224216c4316c77 | |
parent | c4cb544cd5beaa864b3893e4b8d0085393c7dbce (diff) | |
download | vim-git-fa010cdfb115fd2f6bae7ea6f6e63be906b5e347.tar.gz |
patch 8.2.4675: no error for missing expression after :elseifv8.2.4675
Problem: No error for missing expression after :elseif. (Ernie Rael)
Solution: Check for missing expression. (closes #10068)
-rw-r--r-- | src/ex_eval.c | 7 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 10 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 18 insertions, 1 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c index e3c544b89..9a2792a2a 100644 --- 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 diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 54864587f..56842b326 100644 --- 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 diff --git a/src/version.c b/src/version.c index 602366f62..ec9be2896 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4675, +/**/ 4674, /**/ 4673, |