# HG changeset patch # User Bram Moolenaar # Date 1671481803 -3600 # Node ID aa45593ec2ca284e5adbe95e3b97a45ff1eebc74 # Parent d73b5046612f626c0655785492571247aa9fb23f patch 9.0.1081: using "->" with split lines does not always work Commit: https://github.com/vim/vim/commit/34820944ed101e1fbad16d552308f1486e715d27 Author: Bram Moolenaar Date: Mon Dec 19 20:28:38 2022 +0000 patch 9.0.1081: using "->" with split lines does not always work Problem: Using "->" with split lines does not always work. Solution: Avoid trying to get another line. (closes https://github.com/vim/vim/issues/11723) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -4548,11 +4548,19 @@ eval_method( if (**arg != '(' && alias == NULL && (paren = vim_strchr(*arg, '(')) != NULL) { - char_u *deref; - *arg = name; + + // Truncate the name a the "(". Avoid trying to get another line + // by making "getline" NULL. *paren = NUL; - deref = deref_function_name(arg, &tofree, evalarg, verbose); + char_u *(*getline)(int, void *, int, getline_opt_T) = NULL; + if (evalarg != NULL) + { + getline = evalarg->eval_getline; + evalarg->eval_getline = NULL; + } + + char_u *deref = deref_function_name(arg, &tofree, evalarg, verbose); if (deref == NULL) { *arg = name + len; @@ -4563,7 +4571,10 @@ eval_method( name = deref; len = (long)STRLEN(name); } + *paren = '('; + if (getline != NULL) + evalarg->eval_getline = getline; } if (ret == OK) diff --git a/src/testdir/test_user_func.vim b/src/testdir/test_user_func.vim --- a/src/testdir/test_user_func.vim +++ b/src/testdir/test_user_func.vim @@ -179,6 +179,60 @@ func Test_user_method() eval 'bar'->s:addFoo()->assert_equal('barfoo') endfunc +func Test_method_with_linebreaks() + let lines =<< trim END + vim9script + + export def Scan(ll: list): func(func(number)) + return (Emit: func(number)) => { + for v in ll + Emit(v) + endfor + } + enddef + + export def Build(Cont: func(func(number))): list + var result: list = [] + Cont((v) => { + add(result, v) + }) + return result + enddef + + export def Noop(Cont: func(func(number))): func(func(number)) + return (Emit: func(number)) => { + Cont(Emit) + } + enddef + END + call writefile(lines, 'Xlib.vim', 'D') + + let lines =<< trim END + vim9script + + import "./Xlib.vim" as lib + + const x = [1, 2, 3] + + var result = lib.Scan(x)->lib.Noop()->lib.Build() + assert_equal([1, 2, 3], result) + + result = lib.Scan(x)->lib.Noop() + ->lib.Build() + assert_equal([1, 2, 3], result) + + result = lib.Scan(x) + ->lib.Noop()->lib.Build() + assert_equal([1, 2, 3], result) + + result = lib.Scan(x) + ->lib.Noop() + ->lib.Build() + assert_equal([1, 2, 3], result) + END + call v9.CheckScriptSuccess(lines) +endfunc + func Test_failed_call_in_try() try | call UnknownFunc() | catch | endtry endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1081, +/**/ 1080, /**/ 1079,