Mercurial > vim
changeset 30435:c2ef8f0f8ba1 v9.0.0553
patch 9.0.0553: no error for "|" after "{" in lamda
Commit: https://github.com/vim/vim/commit/f5f4e85f0189790ab81c0005b703604721db13d4
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 22 22:03:14 2022 +0100
patch 9.0.0553: no error for "|" after "{" in lamda
Problem: No error for "|" after "{" in lamda.
Solution: Check for invalid "|". (closes https://github.com/vim/vim/issues/11199)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Sep 2022 23:15:03 +0200 |
parents | 9ea0bec4253e |
children | 93abb8acf842 |
files | src/testdir/test_vim9_func.vim src/userfunc.c src/version.c |
diffstat | 3 files changed, 30 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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
--- a/src/userfunc.c +++ b/src/userfunc.c @@ -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))) - { - semsg(_(e_trailing_characters_str), *arg + 1); + *arg = skipwhite(*arg + 1); + if (**arg == '|' || !ends_excmd2(start, *arg)) + { + semsg(_(e_trailing_characters_str), *arg); return FAIL; }