Mercurial > vim
changeset 31497:aa45593ec2ca v9.0.1081
patch 9.0.1081: using "->" with split lines does not always work
Commit: https://github.com/vim/vim/commit/34820944ed101e1fbad16d552308f1486e715d27
Author: Bram Moolenaar <Bram@vim.org>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 19 Dec 2022 21:30:03 +0100 |
parents | d73b5046612f |
children | 725d1f67e7a5 |
files | src/eval.c src/testdir/test_user_func.vim src/version.c |
diffstat | 3 files changed, 70 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- 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<number>): func(func(number)) + return (Emit: func(number)) => { + for v in ll + Emit(v) + endfor + } + enddef + + export def Build(Cont: func(func(number))): list<number> + var result: list<number> = [] + 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