diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-13 08:09:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-13 08:09:21 +0800 |
commit | f516a9ced7238dbb9a3eff453736702fc3d9ec82 (patch) | |
tree | 8da04d6c08300f6b09d944378cd15814af61d533 /src | |
parent | 47ad4c8701b4233aa302c1c21ff08a5f223596c7 (diff) | |
parent | b25197258086faa94ddfaa2a74e1d0eb3695d9b3 (diff) | |
download | rneovim-f516a9ced7238dbb9a3eff453736702fc3d9ec82.tar.gz rneovim-f516a9ced7238dbb9a3eff453736702fc3d9ec82.tar.bz2 rneovim-f516a9ced7238dbb9a3eff453736702fc3d9ec82.zip |
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 (limited to 'src')
-rw-r--r-- | src/nvim/ex_eval.c | 9 | ||||
-rw-r--r-- | src/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 index 8c2ac895cb..bde2f3c801 100644 --- 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 index 44904af160..c93ba9dcfc 100644 --- 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') |