Skip to content

Commit

Permalink
patch 9.0.1081: using "->" with split lines does not always work
Browse files Browse the repository at this point in the history
Problem:    Using "->" with split lines does not always work.
Solution:   Avoid trying to get another line. (closes #11723)
  • Loading branch information
brammool committed Dec 19, 2022
1 parent afa3f1c commit 3482094
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/eval.c
Expand Up @@ -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;
Expand All @@ -4563,7 +4571,10 @@ eval_method(
name = deref;
len = (long)STRLEN(name);
}

*paren = '(';
if (getline != NULL)
evalarg->eval_getline = getline;
}

if (ret == OK)
Expand Down
54 changes: 54 additions & 0 deletions src/testdir/test_user_func.vim
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -695,6 +695,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1081,
/**/
1080,
/**/
Expand Down

0 comments on commit 3482094

Please sign in to comment.