]> granicus.if.org Git - vim/commitdiff
patch 9.0.0553: no error for "|" after "{" in lamda v9.0.0553
authorBram Moolenaar <Bram@vim.org>
Thu, 22 Sep 2022 21:03:14 +0000 (22:03 +0100)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Sep 2022 21:03:14 +0000 (22:03 +0100)
Problem:    No error for "|" after "{" in lamda.
Solution:   Check for invalid "|". (closes #11199)

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

index 4a5546b8ebe9ae97147907ee4f4bf7c518b4ff9c..4d5ff14b144b02015481800abecec0cf0a9735f8 100644 (file)
@@ -1492,6 +1492,29 @@ def Test_lambda_uses_assigned_var()
         'x = filter(["bbb"], (_, v) => v =~ x)'])
 enddef
 
+def Test_lambda_invalid_block()
+  var lines =<< trim END
+      timer_start(0, (_) => { # echo
+          echo 'yes'
+        })
+  END
+  v9.CheckDefAndScriptSuccess(lines)
+
+  lines =<< trim END
+      timer_start(0, (_) => { " echo
+          echo 'yes'
+        })
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E488: Trailing characters: " echo')
+
+  lines =<< trim END
+      timer_start(0, (_) => { | echo
+          echo 'yes'
+        })
+  END
+  v9.CheckDefAndScriptFailure(lines, 'E488: Trailing characters: | echo')
+enddef
+
 def Test_pass_legacy_lambda_to_def_func()
   var lines =<< trim END
       vim9script
index 83221a855547b6fb4ce03b363523e4917551fa78..cc90b95b735dd04d8755d3c0c4e7fcd744e90daa 100644 (file)
@@ -1166,6 +1166,7 @@ lambda_function_body(
        garray_T    *default_args,
        char_u      *ret_type)
 {
+    char_u     *start = *arg;
     int                evaluate = (evalarg->eval_flags & EVAL_EVALUATE);
     garray_T   *gap = &evalarg->eval_ga;
     garray_T   *freegap = &evalarg->eval_freega;
@@ -1179,9 +1180,10 @@ lambda_function_body(
     int                lnum_save = -1;
     linenr_T   sourcing_lnum_top = SOURCING_LNUM;
 
-    if (!ends_excmd2(*arg, skipwhite(*arg + 1)))
+    *arg = skipwhite(*arg + 1);
+    if (**arg == '|' || !ends_excmd2(start, *arg))
     {
-       semsg(_(e_trailing_characters_str), *arg + 1);
+       semsg(_(e_trailing_characters_str), *arg);
        return FAIL;
     }
 
index 505185da500da0891508237d2685897b4b0b5388..57d8259603a27a9e2cf91c12cdfde13e3def098d 100644 (file)
@@ -699,6 +699,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    553,
 /**/
     552,
 /**/