0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.3016: confusing error when expression is followed by comma

Problem:    Confusing error when expression is followed by comma.
Solution:   Give a different error for trailing text. (closes #8395)
This commit is contained in:
Bram Moolenaar 2021-06-17 22:08:30 +02:00
parent 74f4a965bc
commit fae55a9cb0
8 changed files with 24 additions and 13 deletions

View File

@ -2218,12 +2218,15 @@ eval0(
int did_emsg_before = did_emsg;
int called_emsg_before = called_emsg;
int flags = evalarg == NULL ? 0 : evalarg->eval_flags;
int end_error = FALSE;
p = skipwhite(arg);
ret = eval1(&p, rettv, evalarg);
p = skipwhite(p);
if (ret == FAIL || !ends_excmd2(arg, p))
if (ret != FAIL)
end_error = !ends_excmd2(arg, p);
if (ret == FAIL || end_error)
{
if (ret != FAIL)
clear_tv(rettv);
@ -2238,7 +2241,12 @@ eval0(
&& called_emsg == called_emsg_before
&& (flags & EVAL_CONSTANT) == 0
&& (!in_vim9script() || !vim9_bad_comment(p)))
semsg(_(e_invexpr2), arg);
{
if (end_error)
semsg(_(e_trailing_arg), p);
else
semsg(_(e_invexpr2), arg);
}
// Some of the expression may not have been consumed. Do not check for
// a next command to avoid more errors, unless "|" is following, which

View File

@ -165,7 +165,7 @@ func Test_string_concat_scriptversion2()
call assert_fails('echo a . b', 'E15:')
call assert_fails('let a .= b', 'E985:')
call assert_fails('let vers = 1.2.3', 'E15:')
call assert_fails('let vers = 1.2.3', 'E488:')
if has('float')
let f = .5

View File

@ -314,6 +314,7 @@ func Test_let_errors()
let ch = test_null_channel()
call assert_fails('let ch += 1', 'E734:')
endif
call assert_fails('let name = "a" .. "b",', 'E488: Trailing characters: ,')
" This test works only when the language is English
if v:lang == "C" || v:lang =~ '^[Ee]n'

View File

@ -2340,7 +2340,7 @@ def Test_expr7_dict()
CheckScriptFailure(['vim9script', "var x = {xxx: 1,"], 'E723:', 2)
CheckDefAndScriptFailure2(["var x = {['a']: xxx}"], 'E1001:', 'E121:', 1)
CheckDefAndScriptFailure(["var x = {a: 1, a: 2}"], 'E721:', 1)
CheckDefExecAndScriptFailure2(["var x = g:anint.member"], 'E715:', 'E15:', 1)
CheckDefExecAndScriptFailure2(["var x = g:anint.member"], 'E715:', 'E488:', 1)
CheckDefExecAndScriptFailure(["var x = g:dict_empty.member"], 'E716:', 1)
CheckDefExecAndScriptFailure(['var x: dict<number> = {a: 234, b: "1"}'], 'E1012:', 1)
@ -3052,7 +3052,7 @@ func Test_expr7_fails()
call CheckDefAndScriptFailure2(["var x = [notfound]"], "E1001:", 'E121:', 1)
call CheckDefAndScriptFailure2(["var X = () => 123)"], "E488:", 'E15:', 1)
call CheckDefAndScriptFailure(["var X = () => 123)"], 'E488:', 1)
call CheckDefAndScriptFailure(["var x = 123->((x) => x + 5)"], "E107:", 1)
call CheckDefAndScriptFailure(["var x = &notexist"], 'E113:', 1)
@ -3070,7 +3070,7 @@ func Test_expr7_fails()
call CheckDefExecAndScriptFailure(["var x = +g:alist"], 'E745:', 1)
call CheckDefExecAndScriptFailure(["var x = +g:adict"], 'E728:', 1)
call CheckDefAndScriptFailure2(["var x = ''", "var y = x.memb"], 'E715:', 'E15:', 2)
call CheckDefAndScriptFailure2(["var x = ''", "var y = x.memb"], 'E715:', 'E488:', 2)
call CheckDefAndScriptFailure2(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 'E260: Missing name after ->', 1)
@ -3354,8 +3354,8 @@ func Test_expr7_trailing_fails()
endfunc
func Test_expr_fails()
call CheckDefAndScriptFailure2(["var x = '1'is2"], 'E488:', 'E15:', 1)
call CheckDefAndScriptFailure2(["var x = '1'isnot2"], 'E488:', 'E15:', 1)
call CheckDefAndScriptFailure(["var x = '1'is2"], 'E488:', 1)
call CheckDefAndScriptFailure(["var x = '1'isnot2"], 'E488:', 1)
call CheckDefAndScriptFailure2(["CallMe ('yes')"], 'E476:', 'E492:', 1)

View File

@ -3212,7 +3212,7 @@ def Test_vim9_comment_not_compiled()
'if 1# comment3',
' echo "yes"',
'endif',
], 'E15:')
], 'E488:')
CheckScriptFailure([
'vim9script',
@ -3221,7 +3221,7 @@ def Test_vim9_comment_not_compiled()
'elseif 2#comment',
' echo "no"',
'endif',
], 'E15:')
], 'E488:')
CheckScriptSuccess([
'vim9script',
@ -3231,7 +3231,7 @@ def Test_vim9_comment_not_compiled()
CheckScriptFailure([
'vim9script',
'var v = 1# comment6',
], 'E15:')
], 'E488:')
CheckScriptSuccess([
'vim9script',

View File

@ -128,7 +128,7 @@ func Test_global_vars()
\ "!GLOB_BLOB_4\tBLO\t0z12 ab",
\ "!GLOB_LIST_1\tLIS\t1 2",
\ "!GLOB_DICT_1\tDIC\t1 2"], 'Xviminfo')
call assert_fails('rv! Xviminfo', 'E15:')
call assert_fails('rv! Xviminfo', 'E488:')
call assert_equal('123', g:GLOB_BLOB_1)
call assert_equal(1, type(g:GLOB_BLOB_1))
call assert_equal('012', g:GLOB_BLOB_2)

View File

@ -5570,7 +5570,7 @@ func Test_expr_eval_error_msg()
call T(19, '{(1} + CONT(19)', 'E110', "Missing ')'")
call T(20, '("abc"[1) + CONT(20)', 'E111', "Missing ']'")
call T(21, '(1 +) + CONT(21)', 'E15', "Invalid expression")
call T(22, '1 2 + CONT(22)', 'E15', "Invalid expression")
call T(22, '1 2 + CONT(22)', 'E488', "Trailing characters: 2 +")
call T(23, '(1 ? 2) + CONT(23)', 'E109', "Missing ':' after '?'")
call T(24, '("abc) + CONT(24)', 'E114', "Missing quote")
call T(25, "('abc) + CONT(25)", 'E115', "Missing quote")

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3016,
/**/
3015,
/**/