]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda v8.2.1182
authorBram Moolenaar <Bram@vim.org>
Sat, 11 Jul 2020 13:20:48 +0000 (15:20 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 11 Jul 2020 13:20:48 +0000 (15:20 +0200)
Problem:    Vim9: no check for whitespace after comma in lambda.
Solution:   Give error if white space is missing.

src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index ef56a671118f9358069d156c4ac81b3c2561e3d3..edc655aeac4095e149823da7296b2c0979fcce42 100644 (file)
@@ -1067,10 +1067,11 @@ def Test_expr7_list_vim9script()
 enddef
 
 def Test_expr7_lambda()
-  " lambda
   let La = { -> 'result'}
   assert_equal('result', La())
   assert_equal([1, 3, 5], [1, 2, 3]->map({key, val -> key + val}))
+
+  call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
 enddef
 
 def Test_expr7_lambda_vim9script()
index f09ecc9b3b1f5ec57523bcf1524109701b8d6f58..77ada9480995b6e0ab5ce255a7c96e64c89a876d 100644 (file)
@@ -967,7 +967,7 @@ enddef
 
 def Line_continuation_in_lambda(): list<number>
   let x = range(97, 100)
-      ->map({_,v -> nr2char(v)
+      ->map({_, v -> nr2char(v)
           ->toupper()})
       ->reverse()
   return x
index 2f253c95fd6cafdc624c09fbda73685a97b469e8..b5b57ec8804735ca950a92bf70135c075fbc048a 100644 (file)
@@ -266,10 +266,20 @@ get_function_args(
            else if (any_default)
            {
                emsg(_("E989: Non-default argument follows default argument"));
-               mustend = TRUE;
+               goto err_ret;
            }
            if (*p == ',')
+           {
                ++p;
+               // Don't give this error when skipping, it makes the "->" not
+               // found in "{k,v -> x}" and give a confusing error.
+               if (!skip && in_vim9script()
+                                     && !IS_WHITE_OR_NUL(*p) && *p != endchar)
+               {
+                   semsg(_(e_white_after), ",");
+                   goto err_ret;
+               }
+           }
            else
                mustend = TRUE;
        }
index bbb2c28f8b82dac7c03dce0a17846cafcf9a090f..c15cc04610303877eaab876cfb71ba459494d3c0 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1182,
 /**/
     1181,
 /**/