mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.2.3826: Vim9: using "g:Func" as funcref doesn't work in :def function
Problem: Vim9: using "g:Func" as a funcref does not work in a :def function. Solution: Include "g:" in the function name. (closes #9336)
This commit is contained in:
parent
52797bae17
commit
b15cf44c1d
@ -2413,7 +2413,7 @@ def Test_disassemble_dict_stack()
|
|||||||
assert_match('<SNR>\d*_UseMember\_s*' ..
|
assert_match('<SNR>\d*_UseMember\_s*' ..
|
||||||
'var d = {func: Legacy}\_s*' ..
|
'var d = {func: Legacy}\_s*' ..
|
||||||
'\d PUSHS "func"\_s*' ..
|
'\d PUSHS "func"\_s*' ..
|
||||||
'\d PUSHFUNC "Legacy"\_s*' ..
|
'\d PUSHFUNC "g:Legacy"\_s*' ..
|
||||||
'\d NEWDICT size 1\_s*' ..
|
'\d NEWDICT size 1\_s*' ..
|
||||||
'\d STORE $0\_s*' ..
|
'\d STORE $0\_s*' ..
|
||||||
|
|
||||||
|
@ -1232,11 +1232,23 @@ def Test_set_opfunc_to_global_function()
|
|||||||
g:result = getreg('"')->count(' ')
|
g:result = getreg('"')->count(' ')
|
||||||
return ''
|
return ''
|
||||||
enddef
|
enddef
|
||||||
|
# global function works at script level
|
||||||
&operatorfunc = g:CountSpaces
|
&operatorfunc = g:CountSpaces
|
||||||
new
|
new
|
||||||
'a b c d e'->setline(1)
|
'a b c d e'->setline(1)
|
||||||
feedkeys("g@_", 'x')
|
feedkeys("g@_", 'x')
|
||||||
assert_equal(4, g:result)
|
assert_equal(4, g:result)
|
||||||
|
|
||||||
|
&operatorfunc = ''
|
||||||
|
g:result = 0
|
||||||
|
# global function works in :def function
|
||||||
|
def Func()
|
||||||
|
&operatorfunc = g:CountSpaces
|
||||||
|
enddef
|
||||||
|
Func()
|
||||||
|
feedkeys("g@_", 'x')
|
||||||
|
assert_equal(4, g:result)
|
||||||
|
|
||||||
bwipe!
|
bwipe!
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
@ -749,6 +749,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 */
|
||||||
|
/**/
|
||||||
|
3826,
|
||||||
/**/
|
/**/
|
||||||
3825,
|
3825,
|
||||||
/**/
|
/**/
|
||||||
|
@ -1281,12 +1281,26 @@ generate_PUSHBLOB(cctx_T *cctx, blob_T *blob)
|
|||||||
generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
|
generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type)
|
||||||
{
|
{
|
||||||
isn_T *isn;
|
isn_T *isn;
|
||||||
|
char_u *funcname;
|
||||||
|
|
||||||
RETURN_OK_IF_SKIP(cctx);
|
RETURN_OK_IF_SKIP(cctx);
|
||||||
if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
|
if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name);
|
if (name == NULL)
|
||||||
|
funcname = NULL;
|
||||||
|
else if (*name == K_SPECIAL) // script-local
|
||||||
|
funcname = vim_strsave(name);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
funcname = alloc(STRLEN(name) + 3);
|
||||||
|
if (funcname != NULL)
|
||||||
|
{
|
||||||
|
STRCPY(funcname, "g:");
|
||||||
|
STRCPY(funcname + 2, name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
isn->isn_arg.string = funcname;
|
||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user