neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit f516a9ced7238dbb9a3eff453736702fc3d9ec82
parent 47ad4c8701b4233aa302c1c21ff08a5f223596c7
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Sun, 13 Nov 2022 08:09:21 +0800

Merge pull request #21037 from zeertzjq/vim-8.2.4675

vim-patch:8.2.{4675,4676},9.0.0869: no error for missing expression after :elseif
Diffstat:
Msrc/nvim/ex_eval.c | 9++++++++-
Msrc/nvim/testdir/test_vimscript.vim | 20+++++++++++++++-----
2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/nvim/ex_eval.c b/src/nvim/ex_eval.c @@ -899,7 +899,14 @@ void ex_else(exarg_T *eap) if (eap->cmdidx == CMD_elseif) { bool error; - result = eval_to_bool(eap->arg, &error, &eap->nextcmd, skip); + // When skipping we ignore most errors, but a missing expression is + // wrong, perhaps it should have been "else". + // A double quote here is the start of a string, not a comment. + if (skip && *eap->arg != '"' && ends_excmd(*eap->arg)) { + semsg(_(e_invexpr2), eap->arg); + } else { + result = eval_to_bool(eap->arg, &error, &eap->nextcmd, 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/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim @@ -193,6 +193,16 @@ func Test_if_while() call assert_equal('ab3j3b2c2b1f1h1km', g:Xpath) endfunc +" Check double quote after skipped "elseif" does not give error E15 +func Test_skipped_elseif() + if "foo" ==? "foo" + let result = "first" + elseif "foo" ==? "foo" + let result = "second" + endif + call assert_equal('first', result) +endfunc + "------------------------------------------------------------------------------- " Test 4: :return {{{1 "------------------------------------------------------------------------------- @@ -3024,7 +3034,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END - elseif + elseif 1 END call writefile(code, 'Xtest') call AssertException(['source Xtest'], 'Vim(elseif):E582: :elseif without :if') @@ -3032,7 +3042,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END while 1 - elseif + elseif 1 endwhile END call writefile(code, 'Xtest') @@ -3042,7 +3052,7 @@ func Test_nested_if_else_errors() let code =<< trim END try finally - elseif + elseif 1 endtry END call writefile(code, 'Xtest') @@ -3051,7 +3061,7 @@ func Test_nested_if_else_errors() " :elseif without :if let code =<< trim END try - elseif + elseif 1 endtry END call writefile(code, 'Xtest') @@ -3062,7 +3072,7 @@ func Test_nested_if_else_errors() try throw "a" catch /a/ - elseif + elseif 1 endtry END call writefile(code, 'Xtest')