0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.2002: Vim9: lambda argument shadowed by function name

Problem:    Vim9: lambda argument shadowed by function name.
Solution:   Let function name be shadowed by lambda argument. (closes #7313)
This commit is contained in:
Bram Moolenaar
2020-11-17 18:50:44 +01:00
parent 0ba48e8c27
commit 52bf81c2d5
3 changed files with 23 additions and 6 deletions

View File

@@ -1456,6 +1456,15 @@ def Test_nested_lambda()
CheckScriptSuccess(lines) CheckScriptSuccess(lines)
enddef enddef
def Shadowed(): list<number>
var FuncList: list<func: number> = [{ -> 42}]
return FuncList->map({_, Shadowed -> Shadowed()})
enddef
def Test_lambda_arg_shadows_func()
assert_equal([42], Shadowed())
enddef
def Line_continuation_in_def(dir: string = ''): string def Line_continuation_in_def(dir: string = ''): string
var path: string = empty(dir) var path: string = empty(dir)
\ ? 'empty' \ ? 'empty'

View File

@@ -750,6 +750,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 */
/**/
2002,
/**/ /**/
2001, 2001,
/**/ /**/

View File

@@ -2712,13 +2712,19 @@ compile_call(
goto theend; goto theend;
} }
// If we can find the function by name generate the right call. // An argument or local variable can be a function reference, this
// Skip global functions here, a local funcref takes precedence. // overrules a function name.
ufunc = find_func(name, FALSE, cctx); if (lookup_local(namebuf, varlen, cctx) == NULL
if (ufunc != NULL && !func_is_global(ufunc)) && arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
{ {
res = generate_CALL(cctx, ufunc, argcount); // If we can find the function by name generate the right call.
goto theend; // Skip global functions here, a local funcref takes precedence.
ufunc = find_func(name, FALSE, cctx);
if (ufunc != NULL && !func_is_global(ufunc))
{
res = generate_CALL(cctx, ufunc, argcount);
goto theend;
}
} }
// If the name is a variable, load it and use PCALL. // If the name is a variable, load it and use PCALL.