# HG changeset patch # User Bram Moolenaar # Date 1623960903 -7200 # Node ID 21ec48d542a8fdfcf985703e2f40cf988fa87ec4 # Parent 674d99f8705f246bd7b7a28eed7365d2123c9ac6 patch 8.2.3016: confusing error when expression is followed by comma Commit: https://github.com/vim/vim/commit/fae55a9cb0838e4c2e634e55a3468af4a75fbdf2 Author: Bram Moolenaar Date: Thu Jun 17 22:08:30 2021 +0200 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 https://github.com/vim/vim/issues/8395) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -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 diff --git a/src/testdir/test_eval_stuff.vim b/src/testdir/test_eval_stuff.vim --- a/src/testdir/test_eval_stuff.vim +++ b/src/testdir/test_eval_stuff.vim @@ -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 diff --git a/src/testdir/test_let.vim b/src/testdir/test_let.vim --- a/src/testdir/test_let.vim +++ b/src/testdir/test_let.vim @@ -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' diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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 = {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 = ¬exist"], '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) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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', diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim --- a/src/testdir/test_viminfo.vim +++ b/src/testdir/test_viminfo.vim @@ -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) diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim --- a/src/testdir/test_vimscript.vim +++ b/src/testdir/test_vimscript.vim @@ -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") diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3016, +/**/ 3015, /**/ 3014,