mirror of
https://github.com/vim/vim.git
synced 2025-08-22 19:27:53 -04:00
patch 8.2.1343: Vim9: cannot find global function when using g:
Problem: Vim9: cannot find global function when using g: when local function with the same name exists. Solution: Find global function when using g:.
This commit is contained in:
parent
f5a48010ef
commit
333894b195
@ -161,6 +161,21 @@ def Test_nested_global_function()
|
|||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_global_local_function()
|
||||||
|
let lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def g:Func(): string
|
||||||
|
return 'global'
|
||||||
|
enddef
|
||||||
|
def Func(): string
|
||||||
|
return 'local'
|
||||||
|
enddef
|
||||||
|
assert_equal('global', g:Func())
|
||||||
|
assert_equal('local', Func())
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
func TakesOneArg(arg)
|
func TakesOneArg(arg)
|
||||||
echo a:arg
|
echo a:arg
|
||||||
endfunc
|
endfunc
|
||||||
|
@ -789,9 +789,10 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
|
|||||||
|
|
||||||
if (!is_global)
|
if (!is_global)
|
||||||
{
|
{
|
||||||
char_u *after_script = NULL;
|
int vim9script = in_vim9script();
|
||||||
|
char_u *after_script = NULL;
|
||||||
|
|
||||||
if (in_vim9script())
|
if (vim9script)
|
||||||
{
|
{
|
||||||
// Find script-local function before global one.
|
// Find script-local function before global one.
|
||||||
func = find_func_with_sid(name, current_sctx.sc_sid);
|
func = find_func_with_sid(name, current_sctx.sc_sid);
|
||||||
@ -799,7 +800,7 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
|
|||||||
return func;
|
return func;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!in_vim9script()
|
if (!vim9script
|
||||||
&& name[0] == K_SPECIAL
|
&& name[0] == K_SPECIAL
|
||||||
&& name[1] == KS_EXTRA
|
&& name[1] == KS_EXTRA
|
||||||
&& name[2] == KE_SNR)
|
&& name[2] == KE_SNR)
|
||||||
@ -815,7 +816,7 @@ find_func_even_dead(char_u *name, int is_global, cctx_T *cctx)
|
|||||||
else
|
else
|
||||||
after_script = NULL;
|
after_script = NULL;
|
||||||
}
|
}
|
||||||
if (in_vim9script() || after_script != NULL)
|
if (vim9script || after_script != NULL)
|
||||||
{
|
{
|
||||||
// Find imported function before global one.
|
// Find imported function before global one.
|
||||||
imported = find_imported(
|
imported = find_imported(
|
||||||
@ -2086,10 +2087,14 @@ call_func(
|
|||||||
if (error == FCERR_NONE && funcexe->evaluate)
|
if (error == FCERR_NONE && funcexe->evaluate)
|
||||||
{
|
{
|
||||||
char_u *rfname = fname;
|
char_u *rfname = fname;
|
||||||
|
int is_global = FALSE;
|
||||||
|
|
||||||
// Ignore "g:" before a function name.
|
// Skip "g:" before a function name.
|
||||||
if (fp == NULL && fname[0] == 'g' && fname[1] == ':')
|
if (fp == NULL && fname[0] == 'g' && fname[1] == ':')
|
||||||
|
{
|
||||||
|
is_global = TRUE;
|
||||||
rfname = fname + 2;
|
rfname = fname + 2;
|
||||||
|
}
|
||||||
|
|
||||||
rettv->v_type = VAR_NUMBER; // default rettv is number zero
|
rettv->v_type = VAR_NUMBER; // default rettv is number zero
|
||||||
rettv->vval.v_number = 0;
|
rettv->vval.v_number = 0;
|
||||||
@ -2101,7 +2106,7 @@ call_func(
|
|||||||
* User defined function.
|
* User defined function.
|
||||||
*/
|
*/
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
fp = find_func(rfname, FALSE, NULL);
|
fp = find_func(rfname, is_global, NULL);
|
||||||
|
|
||||||
// Trigger FuncUndefined event, may load the function.
|
// Trigger FuncUndefined event, may load the function.
|
||||||
if (fp == NULL
|
if (fp == NULL
|
||||||
@ -2110,13 +2115,13 @@ call_func(
|
|||||||
&& !aborting())
|
&& !aborting())
|
||||||
{
|
{
|
||||||
// executed an autocommand, search for the function again
|
// executed an autocommand, search for the function again
|
||||||
fp = find_func(rfname, FALSE, NULL);
|
fp = find_func(rfname, is_global, NULL);
|
||||||
}
|
}
|
||||||
// Try loading a package.
|
// Try loading a package.
|
||||||
if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
|
if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
|
||||||
{
|
{
|
||||||
// loaded a package, search for the function again
|
// loaded a package, search for the function again
|
||||||
fp = find_func(rfname, FALSE, NULL);
|
fp = find_func(rfname, is_global, NULL);
|
||||||
}
|
}
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
{
|
||||||
@ -2125,7 +2130,7 @@ call_func(
|
|||||||
// If using Vim9 script try not local to the script.
|
// If using Vim9 script try not local to the script.
|
||||||
// TODO: should not do this if the name started with "s:".
|
// TODO: should not do this if the name started with "s:".
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
fp = find_func(p, FALSE, NULL);
|
fp = find_func(p, is_global, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fp != NULL && (fp->uf_flags & FC_DELETED))
|
if (fp != NULL && (fp->uf_flags & FC_DELETED))
|
||||||
@ -2175,6 +2180,7 @@ call_func(
|
|||||||
*/
|
*/
|
||||||
error = call_internal_func(fname, argcount, argvars, rettv);
|
error = call_internal_func(fname, argcount, argvars, rettv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The function call (or "FuncUndefined" autocommand sequence) might
|
* The function call (or "FuncUndefined" autocommand sequence) might
|
||||||
* have been aborted by an error, an interrupt, or an explicitly thrown
|
* have been aborted by an error, an interrupt, or an explicitly thrown
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
1343,
|
||||||
/**/
|
/**/
|
||||||
1342,
|
1342,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user