'enddef',
'DoThat()',
], 'E1084:')
+
+ # Check that global :def function can be replaced and deleted
+ let lines =<< trim END
+ vim9script
+ def g:Global(): string
+ return "yes"
+ enddef
+ assert_equal("yes", g:Global())
+ def! g:Global(): string
+ return "no"
+ enddef
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
+
+ # Check that global function can be replaced by a :def function and deleted
+ lines =<< trim END
+ vim9script
+ func g:Global()
+ return "yes"
+ endfunc
+ assert_equal("yes", g:Global())
+ def! g:Global(): string
+ return "no"
+ enddef
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
+
+ # Check that global :def function can be replaced by a function and deleted
+ lines =<< trim END
+ vim9script
+ def g:Global(): string
+ return "yes"
+ enddef
+ assert_equal("yes", g:Global())
+ func! g:Global()
+ return "no"
+ endfunc
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
enddef
func Test_wrong_type()
func_clear(fp, force);
if (force || fp->uf_dfunc_idx == 0)
func_free(fp, force);
+ else
+ fp->uf_flags |= FC_DEAD;
}
char_u *heredoc_trimmed = NULL;
int vim9script = in_vim9script();
- if (vim9script && eap->forceit)
- {
- emsg(_(e_nobang));
- return NULL;
- }
-
/*
* ":function" without argument: list functions.
*/
}
p = skipwhite(p + 1);
+ // In Vim9 script only global functions can be redefined.
+ if (vim9script && eap->forceit && !is_global)
+ {
+ emsg(_(e_nobang));
+ goto ret_free;
+ }
+
ga_init2(&newlines, (int)sizeof(char_u *), 3);
if (!eap->skip && name_arg == NULL)