Mirror of the Vim source from https://github.com/vim/vim
Revision | aa45593ec2ca284e5adbe95e3b97a45ff1eebc74 (tree) |
---|---|
Time | 2022-12-20 05:30:03 |
Author | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -4548,11 +4548,19 @@ | ||
4548 | 4548 | if (**arg != '(' && alias == NULL |
4549 | 4549 | && (paren = vim_strchr(*arg, '(')) != NULL) |
4550 | 4550 | { |
4551 | - char_u *deref; | |
4552 | - | |
4553 | 4551 | *arg = name; |
4552 | + | |
4553 | + // Truncate the name a the "(". Avoid trying to get another line | |
4554 | + // by making "getline" NULL. | |
4554 | 4555 | *paren = NUL; |
4555 | - deref = deref_function_name(arg, &tofree, evalarg, verbose); | |
4556 | + char_u *(*getline)(int, void *, int, getline_opt_T) = NULL; | |
4557 | + if (evalarg != NULL) | |
4558 | + { | |
4559 | + getline = evalarg->eval_getline; | |
4560 | + evalarg->eval_getline = NULL; | |
4561 | + } | |
4562 | + | |
4563 | + char_u *deref = deref_function_name(arg, &tofree, evalarg, verbose); | |
4556 | 4564 | if (deref == NULL) |
4557 | 4565 | { |
4558 | 4566 | *arg = name + len; |
@@ -4563,7 +4571,10 @@ | ||
4563 | 4571 | name = deref; |
4564 | 4572 | len = (long)STRLEN(name); |
4565 | 4573 | } |
4574 | + | |
4566 | 4575 | *paren = '('; |
4576 | + if (getline != NULL) | |
4577 | + evalarg->eval_getline = getline; | |
4567 | 4578 | } |
4568 | 4579 | |
4569 | 4580 | if (ret == OK) |
@@ -179,6 +179,60 @@ | ||
179 | 179 | eval 'bar'->s:addFoo()->assert_equal('barfoo') |
180 | 180 | endfunc |
181 | 181 | |
182 | +func Test_method_with_linebreaks() | |
183 | + let lines =<< trim END | |
184 | + vim9script | |
185 | + | |
186 | + export def Scan(ll: list<number>): func(func(number)) | |
187 | + return (Emit: func(number)) => { | |
188 | + for v in ll | |
189 | + Emit(v) | |
190 | + endfor | |
191 | + } | |
192 | + enddef | |
193 | + | |
194 | + export def Build(Cont: func(func(number))): list<number> | |
195 | + var result: list<number> = [] | |
196 | + Cont((v) => { | |
197 | + add(result, v) | |
198 | + }) | |
199 | + return result | |
200 | + enddef | |
201 | + | |
202 | + export def Noop(Cont: func(func(number))): func(func(number)) | |
203 | + return (Emit: func(number)) => { | |
204 | + Cont(Emit) | |
205 | + } | |
206 | + enddef | |
207 | + END | |
208 | + call writefile(lines, 'Xlib.vim', 'D') | |
209 | + | |
210 | + let lines =<< trim END | |
211 | + vim9script | |
212 | + | |
213 | + import "./Xlib.vim" as lib | |
214 | + | |
215 | + const x = [1, 2, 3] | |
216 | + | |
217 | + var result = lib.Scan(x)->lib.Noop()->lib.Build() | |
218 | + assert_equal([1, 2, 3], result) | |
219 | + | |
220 | + result = lib.Scan(x)->lib.Noop() | |
221 | + ->lib.Build() | |
222 | + assert_equal([1, 2, 3], result) | |
223 | + | |
224 | + result = lib.Scan(x) | |
225 | + ->lib.Noop()->lib.Build() | |
226 | + assert_equal([1, 2, 3], result) | |
227 | + | |
228 | + result = lib.Scan(x) | |
229 | + ->lib.Noop() | |
230 | + ->lib.Build() | |
231 | + assert_equal([1, 2, 3], result) | |
232 | + END | |
233 | + call v9.CheckScriptSuccess(lines) | |
234 | +endfunc | |
235 | + | |
182 | 236 | func Test_failed_call_in_try() |
183 | 237 | try | call UnknownFunc() | catch | endtry |
184 | 238 | endfunc |
@@ -696,6 +696,8 @@ | ||
696 | 696 | static int included_patches[] = |
697 | 697 | { /* Add new patch number below this line */ |
698 | 698 | /**/ |
699 | + 1081, | |
700 | +/**/ | |
699 | 701 | 1080, |
700 | 702 | /**/ |
701 | 703 | 1079, |