]> granicus.if.org Git - vim/commitdiff
patch 8.2.2002: Vim9: lambda argument shadowed by function name v8.2.2002
authorBram Moolenaar <Bram@vim.org>
Tue, 17 Nov 2020 17:50:44 +0000 (18:50 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 17 Nov 2020 17:50:44 +0000 (18:50 +0100)
Problem:    Vim9: lambda argument shadowed by function name.
Solution:   Let function name be shadowed by lambda argument. (closes #7313)

src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index bbfce23c4ad7419f5af589c472734872b4b809a5..e11564f08398970ec44f5c0295e2794c7693f363 100644 (file)
@@ -1456,6 +1456,15 @@ def Test_nested_lambda()
   CheckScriptSuccess(lines)
 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
   var path: string = empty(dir)
           \ ? 'empty'
index 4b91cf1ca1c7e2e70f05396588e6b53aad90822d..7f4996761ff3a056a9d7144f3ca1e6158cc6a609 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2002,
 /**/
     2001,
 /**/
index 6b2b766bea33a6e978870a37bae5a800c6322d73..ebe48548e2a9c2358504d53ceb1aeb97d89b52c6 100644 (file)
@@ -2712,13 +2712,19 @@ compile_call(
        goto theend;
     }
 
-    // If we can find the function by name generate the right call.
-    // 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;
+    // An argument or local variable can be a function reference, this
+    // overrules a function name.
+    if (lookup_local(namebuf, varlen, cctx) == NULL
+           && arg_exists(namebuf, varlen, NULL, NULL, NULL, cctx) != OK)
+    {
+       // If we can find the function by name generate the right call.
+       // 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.