File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -909,7 +909,7 @@ ex_let(exarg_T *eap)
909909}
910910
911911/*
912- * Assign the typevalue "tv" to the variable or variables at "arg_start".
912+ * Assign the typeval "tv" to the variable or variables at "arg_start".
913913 * Handles both "var" with any type and "[var, var; var]" with a list type.
914914 * When "op" is not NULL it points to a string with characters that
915915 * must appear after the variable(s). Use "+", "-" or "." for add, subtract
@@ -3179,6 +3179,7 @@ set_var_const(
31793179
31803180 if (di != NULL )
31813181 {
3182+ // Item already exists. Allowed to replace when reloading.
31823183 if ((di -> di_flags & DI_FLAGS_RELOAD ) == 0 )
31833184 {
31843185 if (flags & (ASSIGN_CONST | ASSIGN_FINAL ))
@@ -3269,6 +3270,14 @@ set_var_const(
32693270 }
32703271 else
32713272 {
3273+ // Item not found, check if a function already exists.
3274+ if (is_script_local && (flags & (ASSIGN_NO_DECL | ASSIGN_DECL )) == 0
3275+ && lookup_scriptitem (name , STRLEN (name ), NULL ) == OK )
3276+ {
3277+ semsg (_ (e_redefining_script_item_str ), name );
3278+ goto failed ;
3279+ }
3280+
32723281 // add a new variable
32733282 if (vim9script && is_script_local && (flags & ASSIGN_NO_DECL ))
32743283 {
Original file line number Diff line number Diff line change @@ -1515,6 +1515,17 @@ def Test_script_reload_change_type()
15151515 delete (' Xreload.vim' )
15161516enddef
15171517
1518+ def Test_script_var_shadows_function ()
1519+ var lines = << trim END
1520+ vim9script
1521+ def Func (): number
1522+ return 123
1523+ enddef
1524+ var Func = 1
1525+ END
1526+ CheckScriptFailure (lines , ' E1041:' , 5 )
1527+ enddef
1528+
15181529def s: RetSome (): string
15191530 return ' some'
15201531enddef
Original file line number Diff line number Diff line change @@ -750,6 +750,8 @@ static char *(features[]) =
750750
751751static int included_patches [] =
752752{ /* Add new patch number below this line */
753+ /**/
754+ 2567 ,
753755/**/
754756 2566 ,
755757/**/
You can’t perform that action at this time.
0 commit comments