Problem: Confusing error when expression is followed by comma.
Solution: Give a different error for trailing text. (closes #8395)
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);
&& 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
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
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'
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)
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 = ¬exist"], 'E113:', 1)
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)
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)
'if 1# comment3',
' echo "yes"',
'endif',
- ], 'E15:')
+ ], 'E488:')
CheckScriptFailure([
'vim9script',
'elseif 2#comment',
' echo "no"',
'endif',
- ], 'E15:')
+ ], 'E488:')
CheckScriptSuccess([
'vim9script',
CheckScriptFailure([
'vim9script',
'var v = 1# comment6',
- ], 'E15:')
+ ], 'E488:')
CheckScriptSuccess([
'vim9script',
\ "!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)
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")
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 3016,
/**/
3015,
/**/