@@ -2805,12 +2805,15 @@ get_script_local_ht(void)
28052805
28062806/*
28072807 * Look for "name[len]" in script-local variables and functions.
2808+ * When "cmd" is TRUE it must look like a command, a function must be followed
2809+ * by "(" or "->".
28082810 * Return OK when found, FAIL when not found.
28092811 */
28102812 int
28112813lookup_scriptitem (
28122814 char_u * name ,
28132815 size_t len ,
2816+ int cmd ,
28142817 cctx_T * dummy UNUSED )
28152818{
28162819 hashtab_T * ht = get_script_local_ht ();
@@ -2845,19 +2848,26 @@ lookup_scriptitem(
28452848 if (p != buffer )
28462849 vim_free (p );
28472850
2851+ // Find a function, so that a following "->" works.
2852+ // When used as a command require "(" or "->" to follow, "Cmd" is a user
2853+ // command while "Cmd()" is a function call.
28482854 if (res != OK )
28492855 {
2850- // Find a function, so that a following "->" works. Skip "g:" before a
2851- // function name.
2852- // Do not check for an internal function, since it might also be a
2853- // valid command, such as ":split" versuse "split()".
2854- if (name [0 ] == 'g' && name [1 ] == ':' )
2856+ p = skipwhite (name + len );
2857+
2858+ if (!cmd || name [len ] == '(' || (p [0 ] == '-' && p [1 ] == '>' ))
28552859 {
2856- is_global = TRUE;
2857- fname = name + 2 ;
2860+ // Do not check for an internal function, since it might also be a
2861+ // valid command, such as ":split" versus "split()".
2862+ // Skip "g:" before a function name.
2863+ if (name [0 ] == 'g' && name [1 ] == ':' )
2864+ {
2865+ is_global = TRUE;
2866+ fname = name + 2 ;
2867+ }
2868+ if (find_func (fname , is_global , NULL ) != NULL )
2869+ res = OK ;
28582870 }
2859- if (find_func (fname , is_global , NULL ) != NULL )
2860- res = OK ;
28612871 }
28622872
28632873 return res ;
@@ -3288,7 +3298,7 @@ set_var_const(
32883298 {
32893299 // Item not found, check if a function already exists.
32903300 if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL )) == 0
3291- && lookup_scriptitem (name , STRLEN (name ), NULL ) == OK )
3301+ && lookup_scriptitem (name , STRLEN (name ), FALSE , NULL ) == OK )
32923302 {
32933303 semsg (_ (e_redefining_script_item_str ), name );
32943304 goto failed ;
0 commit comments