]> granicus.if.org Git - vim/commitdiff
patch 8.2.3016: confusing error when expression is followed by comma v8.2.3016
authorBram Moolenaar <Bram@vim.org>
Thu, 17 Jun 2021 20:08:30 +0000 (22:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 17 Jun 2021 20:08:30 +0000 (22:08 +0200)
Problem:    Confusing error when expression is followed by comma.
Solution:   Give a different error for trailing text. (closes #8395)

src/eval.c
src/testdir/test_eval_stuff.vim
src/testdir/test_let.vim
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_script.vim
src/testdir/test_viminfo.vim
src/testdir/test_vimscript.vim
src/version.c

index ffc7122cde4cd9ee5096b95120dafde1b0e7770d..33ea8504a269ecf95ab90ccbf06b570bad75f936 100644 (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
index 0c1e75df595e7eacf50e462b1e70ed6850fdf5f9..1fbb74bc4eb6c4273b73d2a0e07680d9c4ed38cb 100644 (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
index 1b8f74bcfef4406ec624ece9509f2514814c5d72..c05a4cbc20bef429d50b8e472c4f880f87f47d91 100644 (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'
index d7fb1df825c1f7c6593f5ec1e9b4a6b4f0ae95df..974ca8548b78c3841c3644d5ef0ba3b842de2c23 100644 (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)
 
index 9237fdfad8280ea91e70e33a8145eb9fd0d7a13d..4b0ab2bad71cbc890df90d521d8c32ab67c98b98 100644 (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',
index e70fed898aa59e3400887741a72739e21b4e350c..0518b91d06ea67e7b555edf622772fe335b776c4 100644 (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)
index 89c100189b567b6cd28aa6cdcbc7ebe8524d4fbd..de876589afcbfdfdf75deebf8d147fff67f81a7e 100644 (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")
index 4f33d35d87932043ecf77d7ff610aed9ad175698..a03b3fe13c368249f1f8746ee33ee6b4ef9b505d 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3016,
 /**/
     3015,
 /**/