mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.1290: Vim9: cannot replace a global function
Problem: Vim9: cannot replace a global function. Solution: Allow for "!" on a global function. (closes #6524) Also fix that :delfunc on a :def function only made it empty.
This commit is contained in:
parent
c841afff6a
commit
925e9fd633
@ -468,6 +468,54 @@ def Test_delfunction()
|
|||||||
'enddef',
|
'enddef',
|
||||||
'DoThat()',
|
'DoThat()',
|
||||||
], 'E1084:')
|
], '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
|
enddef
|
||||||
|
|
||||||
func Test_wrong_type()
|
func Test_wrong_type()
|
||||||
|
@ -1148,6 +1148,8 @@ func_clear_free(ufunc_T *fp, int force)
|
|||||||
func_clear(fp, force);
|
func_clear(fp, force);
|
||||||
if (force || fp->uf_dfunc_idx == 0)
|
if (force || fp->uf_dfunc_idx == 0)
|
||||||
func_free(fp, force);
|
func_free(fp, force);
|
||||||
|
else
|
||||||
|
fp->uf_flags |= FC_DEAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2557,12 +2559,6 @@ def_function(exarg_T *eap, char_u *name_arg)
|
|||||||
char_u *heredoc_trimmed = NULL;
|
char_u *heredoc_trimmed = NULL;
|
||||||
int vim9script = in_vim9script();
|
int vim9script = in_vim9script();
|
||||||
|
|
||||||
if (vim9script && eap->forceit)
|
|
||||||
{
|
|
||||||
emsg(_(e_nobang));
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ":function" without argument: list functions.
|
* ":function" without argument: list functions.
|
||||||
*/
|
*/
|
||||||
@ -2732,6 +2728,13 @@ def_function(exarg_T *eap, char_u *name_arg)
|
|||||||
}
|
}
|
||||||
p = skipwhite(p + 1);
|
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);
|
ga_init2(&newlines, (int)sizeof(char_u *), 3);
|
||||||
|
|
||||||
if (!eap->skip && name_arg == NULL)
|
if (!eap->skip && name_arg == NULL)
|
||||||
|
@ -754,6 +754,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1290,
|
||||||
/**/
|
/**/
|
||||||
1289,
|
1289,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user