Skip to content

Commit 2e2d758

Browse files
committed
patch 8.2.2566: Vim9: Function name is not recognized
Problem: Vim9: Function name is not recognized. Solution: Change lookup_scriptvar() to also find function names. (closes #7770)
1 parent f76ec1e commit 2e2d758

File tree

6 files changed

+43
-6
lines changed

6 files changed

+43
-6
lines changed

src/evalvars.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2788,11 +2788,11 @@ get_script_local_ht(void)
27882788
}
27892789

27902790
/*
2791-
* Look for "name[len]" in script-local variables.
2791+
* Look for "name[len]" in script-local variables and functions.
27922792
* Return OK when found, FAIL when not found.
27932793
*/
27942794
int
2795-
lookup_scriptvar(
2795+
lookup_scriptitem(
27962796
char_u *name,
27972797
size_t len,
27982798
cctx_T *dummy UNUSED)
@@ -2802,6 +2802,8 @@ lookup_scriptvar(
28022802
char_u *p;
28032803
int res;
28042804
hashitem_T *hi;
2805+
int is_global = FALSE;
2806+
char_u *fname = name;
28052807

28062808
if (ht == NULL)
28072809
return FAIL;
@@ -2824,9 +2826,24 @@ lookup_scriptvar(
28242826
// if not script-local, then perhaps imported
28252827
if (res == FAIL && find_imported(p, 0, NULL) != NULL)
28262828
res = OK;
2827-
28282829
if (p != buffer)
28292830
vim_free(p);
2831+
2832+
if (res != OK)
2833+
{
2834+
// Find a function, so that a following "->" works. Skip "g:" before a
2835+
// function name.
2836+
// Do not check for an internal function, since it might also be a
2837+
// valid command, such as ":split" versuse "split()".
2838+
if (name[0] == 'g' && name[1] == ':')
2839+
{
2840+
is_global = TRUE;
2841+
fname = name + 2;
2842+
}
2843+
if (find_func(fname, is_global, NULL) != NULL)
2844+
res = OK;
2845+
}
2846+
28302847
return res;
28312848
}
28322849

src/ex_docmd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1829,7 +1829,7 @@ do_one_cmd(
18291829
if (ea.cmd == cmd + 1 && *cmd == '$')
18301830
// should be "$VAR = val"
18311831
--ea.cmd;
1832-
p = find_ex_command(&ea, NULL, lookup_scriptvar, NULL);
1832+
p = find_ex_command(&ea, NULL, lookup_scriptitem, NULL);
18331833
if (ea.cmdidx == CMD_SIZE)
18341834
{
18351835
char_u *ar = skip_range(ea.cmd, TRUE, NULL);

src/proto/evalvars.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void check_vars(char_u *name, int len);
6161
dictitem_T *find_var(char_u *name, hashtab_T **htp, int no_autoload);
6262
dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, char_u *varname, int no_autoload);
6363
hashtab_T *get_script_local_ht(void);
64-
int lookup_scriptvar(char_u *name, size_t len, cctx_T *dummy);
64+
int lookup_scriptitem(char_u *name, size_t len, cctx_T *dummy);
6565
hashtab_T *find_var_ht(char_u *name, char_u **varname);
6666
char_u *get_var_value(char_u *name);
6767
void new_script_vars(scid_T id);

src/testdir/test_vim9_cmd.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ def Test_method_call_linebreak()
371371
MethodAfterLinebreak('foobar')
372372
assert_equal('foobar', getline(1))
373373
bwipe!
374+
375+
lines =<< trim END
376+
vim9script
377+
def Foo(): string
378+
return '# some text'
379+
enddef
380+
381+
def Bar(F: func): string
382+
return F()
383+
enddef
384+
385+
Foo
386+
->Bar()
387+
->setline(1)
388+
END
389+
CheckScriptSuccess(lines)
390+
assert_equal('# some text', getline(1))
391+
bwipe!
374392
enddef
375393

376394
def Test_method_call_whitespace()

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+
2566,
753755
/**/
754756
2565,
755757
/**/

src/vim9script.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ ex_export(exarg_T *eap)
138138
}
139139

140140
eap->cmd = eap->arg;
141-
(void)find_ex_command(eap, NULL, lookup_scriptvar, NULL);
141+
(void)find_ex_command(eap, NULL, lookup_scriptitem, NULL);
142142
switch (eap->cmdidx)
143143
{
144144
case CMD_let:

0 commit comments

Comments
 (0)