Skip to content

Commit 6914e87

Browse files
committed
patch 8.2.2575: Vim9: a function name with "->" in the next line doesn't work
Problem: Vim9: a function name with "->" in the next line doesn't work. Solution: Recognize a function name by itself. (closes #7770)
1 parent 04947cc commit 6914e87

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/testdir/test_vim9_cmd.vim

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,25 @@ def Test_method_call_linebreak()
355355
END
356356
CheckDefAndScriptSuccess(lines)
357357

358+
lines =<< trim END
359+
new
360+
def Foo(): string
361+
return 'the text'
362+
enddef
363+
def Bar(F: func): string
364+
return F()
365+
enddef
366+
def Test()
367+
Foo
368+
->Bar()
369+
->setline(1)
370+
enddef
371+
Test()
372+
assert_equal('the text', getline(1))
373+
bwipe!
374+
END
375+
CheckDefAndScriptSuccess(lines)
376+
358377
lines =<< trim END
359378
new
360379
g:shortlist

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2575,
753755
/**/
754756
2574,
755757
/**/

src/vim9compile.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,26 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
386386
|| find_imported(name, len, cctx) != NULL;
387387
}
388388

389+
/*
390+
* Return TRUE if "name" is a local variable, argument, script variable,
391+
* imported or function.
392+
*/
393+
static int
394+
item_exists(char_u *name, size_t len, cctx_T *cctx)
395+
{
396+
int is_global;
397+
398+
if (variable_exists(name, len, cctx))
399+
return TRUE;
400+
401+
// Find a function, so that a following "->" works. Skip "g:" before a
402+
// function name.
403+
// Do not check for an internal function, since it might also be a
404+
// valid command, such as ":split" versuse "split()".
405+
is_global = (name[0] == 'g' && name[1] == ':');
406+
return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
407+
}
408+
389409
/*
390410
* Check if "p[len]" is already defined, either in script "import_sid" or in
391411
* compilation context "cctx". "cctx" is NULL at the script level.
@@ -728,7 +748,7 @@ get_compare_isn(exprtype_T exprtype, vartype_T type1, vartype_T type2)
728748
}
729749
else if (type1 == VAR_ANY || type2 == VAR_ANY
730750
|| ((type1 == VAR_NUMBER || type1 == VAR_FLOAT)
731-
&& (type2 == VAR_NUMBER || type2 ==VAR_FLOAT)))
751+
&& (type2 == VAR_NUMBER || type2 == VAR_FLOAT)))
732752
isntype = ISN_COMPAREANY;
733753

734754
if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT)
@@ -8399,8 +8419,7 @@ compile_def_function(
83998419
}
84008420
}
84018421
p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
8402-
: (int (*)(char_u *, size_t, cctx_T *))variable_exists,
8403-
&cctx);
8422+
: (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx);
84048423

84058424
if (p == NULL)
84068425
{

0 commit comments

Comments
 (0)