@@ -1138,3 +1138,30 @@ func Test_func_range_with_edit()
11381138 call delete (' Xfuncrange2' )
11391139 bwipe!
11401140endfunc
1141+
1142+ func Test_func_exists_on_reload ()
1143+ call writefile ([' func ExistingFunction()' , ' echo "yes"' , ' endfunc' ], ' Xfuncexists' )
1144+ call assert_equal (0 , exists (' *ExistingFunction' ))
1145+ source Xfuncexists
1146+ call assert_equal (1 , exists (' *ExistingFunction' ))
1147+ " Redefining a function when reloading a script is OK.
1148+ source Xfuncexists
1149+ call assert_equal (1 , exists (' *ExistingFunction' ))
1150+
1151+ " But redefining in another script is not OK.
1152+ call writefile ([' func ExistingFunction()' , ' echo "yes"' , ' endfunc' ], ' Xfuncexists2' )
1153+ call assert_fails (' source Xfuncexists2' , ' E122:' )
1154+
1155+ delfunc ExistingFunction
1156+ call assert_equal (0 , exists (' *ExistingFunction' ))
1157+ call writefile ([
1158+ \ ' func ExistingFunction()' , ' echo "yes"' , ' endfunc' ,
1159+ \ ' func ExistingFunction()' , ' echo "no"' , ' endfunc' ,
1160+ \ ], ' Xfuncexists' )
1161+ call assert_fails (' source Xfuncexists' , ' E122:' )
1162+ call assert_equal (1 , exists (' *ExistingFunction' ))
1163+
1164+ call delete (' Xfuncexists2' )
1165+ call delete (' Xfuncexists' )
1166+ delfunc ExistingFunction
1167+ endfunc
0 commit comments