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
This commit is contained in:
zeertzjq 2022-11-13 08:09:21 +08:00 committed by GitHub
commit f516a9ced7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -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

View File

@ -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')