summaryrefslogtreecommitdiff
path: root/src/vim9compile.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-03-14 13:21:35 +0100
committerBram Moolenaar <Bram@vim.org>2021-03-14 13:21:35 +0100
commit77b10ffad4ebad15022614be4db2745f6a90f405 (patch)
tree8319b6d1ba747e28f7ef57082978d9be464049c5 /src/vim9compile.c
parent2e34c34be1393027a761ecbccd8f267d52ca7bc1 (diff)
downloadvim-git-77b10ffad4ebad15022614be4db2745f6a90f405.tar.gz
patch 8.2.2603: Vim9: no effect if user command is also a functionv8.2.2603
Problem: Vim9: no effect if user command is also a function. Solution: Check for paren following. (closes #7960)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r--src/vim9compile.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 1bb30ca0c..3fef9bd6b 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -391,19 +391,29 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
* imported or function.
*/
static int
-item_exists(char_u *name, size_t len, cctx_T *cctx)
+item_exists(char_u *name, size_t len, int cmd UNUSED, cctx_T *cctx)
{
int is_global;
+ char_u *p;
if (variable_exists(name, len, cctx))
return TRUE;
- // Find a function, so that a following "->" works. Skip "g:" before a
- // function name.
- // Do not check for an internal function, since it might also be a
- // valid command, such as ":split" versuse "split()".
- is_global = (name[0] == 'g' && name[1] == ':');
- return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
+ // This is similar to what is in lookup_scriptitem():
+ // Find a function, so that a following "->" works.
+ // Require "(" or "->" to follow, "Cmd" is a user command while "Cmd()" is
+ // a function call.
+ p = skipwhite(name + len);
+
+ if (name[len] == '(' || (p[0] == '-' && p[1] == '>'))
+ {
+ // Do not check for an internal function, since it might also be a
+ // valid command, such as ":split" versuse "split()".
+ // Skip "g:" before a function name.
+ is_global = (name[0] == 'g' && name[1] == ':');
+ return find_func(is_global ? name + 2 : name, is_global, cctx) != NULL;
+ }
+ return FALSE;
}
/*
@@ -8429,8 +8439,8 @@ compile_def_function(
}
}
}
- p = find_ex_command(&ea, NULL, starts_with_colon ? NULL
- : (int (*)(char_u *, size_t, cctx_T *))item_exists, &cctx);
+ p = find_ex_command(&ea, NULL, starts_with_colon
+ ? NULL : item_exists, &cctx);
if (p == NULL)
{