]> granicus.if.org Git - vim/commitdiff
patch 8.2.1861: Vim9: no specific error when parsing lambda fails v8.2.1861
authorBram Moolenaar <Bram@vim.org>
Sun, 18 Oct 2020 16:03:17 +0000 (18:03 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 18 Oct 2020 16:03:17 +0000 (18:03 +0200)
Problem:    Vim9: no specific error when parsing lambda fails.
Solution:   Also give syntax errors when not evaluating. (closes #7154)

src/dict.c
src/testdir/test_vim9_expr.vim
src/version.c

index 5725140df31cbba78b0680873e1d7ce60282cc7b..503f5a522370aa7c77a7efad7f7a07dfc657037b 100644 (file)
@@ -860,13 +860,10 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
            *arg = skipwhite(*arg);
        if (**arg != ':')
        {
-           if (evaluate)
-           {
-               if (*skipwhite(*arg) == ':')
-                   semsg(_(e_no_white_space_allowed_before_str), ":");
-               else
-                   semsg(_(e_missing_dict_colon), *arg);
-           }
+           if (*skipwhite(*arg) == ':')
+               semsg(_(e_no_white_space_allowed_before_str), ":");
+           else
+               semsg(_(e_missing_dict_colon), *arg);
            clear_tv(&tvkey);
            goto failret;
        }
@@ -899,8 +896,7 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
            item = dict_find(d, key, -1);
            if (item != NULL)
            {
-               if (evaluate)
-                   semsg(_(e_duplicate_key), key);
+               semsg(_(e_duplicate_key), key);
                clear_tv(&tvkey);
                clear_tv(&tv);
                goto failret;
@@ -937,21 +933,17 @@ eval_dict(char_u **arg, typval_T *rettv, evalarg_T *evalarg, int literal)
            break;
        if (!had_comma)
        {
-           if (evaluate)
-           {
-               if (**arg == ',')
-                   semsg(_(e_no_white_space_allowed_before_str), ",");
-               else
-                   semsg(_(e_missing_dict_comma), *arg);
-           }
+           if (**arg == ',')
+               semsg(_(e_no_white_space_allowed_before_str), ",");
+           else
+               semsg(_(e_missing_dict_comma), *arg);
            goto failret;
        }
     }
 
     if (**arg != '}')
     {
-       if (evaluate)
-           semsg(_(e_missing_dict_end), *arg);
+       semsg(_(e_missing_dict_end), *arg);
 failret:
        if (d != NULL)
            dict_free(d);
index 950c38ceb01185786bfa0dac2e71c768a34d3d69..a4e7c510e5b5cf88f0aa05c9f202ce9f48e701f5 100644 (file)
@@ -1805,6 +1805,13 @@ def Test_expr7_lambda()
   CheckDefExecFailure(["var s = 'asdf'->{a -> a}('x', 'y')"],
         'E1106: 2 arguments too many')
   CheckDefFailure(["echo 'asdf'->{a -> a}(x)"], 'E1001:', 1)
+
+  CheckDefSuccess(['var Fx = {a -> #{k1: 0,', ' k2: 1}}'])
+  CheckDefFailure(['var Fx = {a -> #{k1: 0', ' k2: 1}}'], 'E722:', 2)
+  CheckDefFailure(['var Fx = {a -> #{k1: 0,', ' k2 1}}'], 'E720:', 2)
+
+  CheckDefSuccess(['var Fx = {a -> [0,', ' 1]}'])
+  CheckDefFailure(['var Fx = {a -> [0', ' 1]}'], 'E696:', 2)
 enddef
 
 def Test_expr7_lambda_vim9script()
@@ -2371,7 +2378,7 @@ func Test_expr7_fails()
   call CheckDefFailure(["'yes'->", "Echo()"], 'E488: Trailing characters: ->', 1)
 
   call CheckDefExecFailure(["[1, 2->len()"], 'E697:', 2)
-  call CheckDefExecFailure(["#{a: 1->len()"], 'E488:', 1)
+  call CheckDefExecFailure(["#{a: 1->len()"], 'E722:', 1)
   call CheckDefExecFailure(["{'a': 1->len()"], 'E723:', 2)
 endfunc
 
index 7720998fc1e5cf5cd3b06bdd35706abac7334efe..5a5344315b4ac25cc10e3b4c69b43c63cf2f5da5 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1861,
 /**/
     1860,
 /**/