Mercurial > vim
diff src/evalvars.c @ 24124:f4061617c438 v8.2.2603
patch 8.2.2603: Vim9: no effect if user command is also a function
Commit: https://github.com/vim/vim/commit/77b10ffad4ebad15022614be4db2745f6a90f405
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 14 13:21:35 2021 +0100
patch 8.2.2603: Vim9: no effect if user command is also a function
Problem: Vim9: no effect if user command is also a function.
Solution: Check for paren following. (closes https://github.com/vim/vim/issues/7960)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 14 Mar 2021 13:30:03 +0100 |
parents | 0346a59ed5bf |
children | e5cd25f7ffcd |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -2805,12 +2805,15 @@ get_script_local_ht(void) /* * Look for "name[len]" in script-local variables and functions. + * When "cmd" is TRUE it must look like a command, a function must be followed + * by "(" or "->". * Return OK when found, FAIL when not found. */ int lookup_scriptitem( char_u *name, size_t len, + int cmd, cctx_T *dummy UNUSED) { hashtab_T *ht = get_script_local_ht(); @@ -2845,19 +2848,26 @@ lookup_scriptitem( if (p != buffer) vim_free(p); + // Find a function, so that a following "->" works. + // When used as a command require "(" or "->" to follow, "Cmd" is a user + // command while "Cmd()" is a function call. if (res != OK) { - // 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()". - if (name[0] == 'g' && name[1] == ':') + p = skipwhite(name + len); + + if (!cmd || name[len] == '(' || (p[0] == '-' && p[1] == '>')) { - is_global = TRUE; - fname = name + 2; + // Do not check for an internal function, since it might also be a + // valid command, such as ":split" versus "split()". + // Skip "g:" before a function name. + if (name[0] == 'g' && name[1] == ':') + { + is_global = TRUE; + fname = name + 2; + } + if (find_func(fname, is_global, NULL) != NULL) + res = OK; } - if (find_func(fname, is_global, NULL) != NULL) - res = OK; } return res; @@ -3288,7 +3298,7 @@ set_var_const( { // Item not found, check if a function already exists. if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL)) == 0 - && lookup_scriptitem(name, STRLEN(name), NULL) == OK) + && lookup_scriptitem(name, STRLEN(name), FALSE, NULL) == OK) { semsg(_(e_redefining_script_item_str), name); goto failed;