]> granicus.if.org Git - vim/commitdiff
patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level v8.2.2739
authorBram Moolenaar <Bram@vim.org>
Fri, 9 Apr 2021 15:24:52 +0000 (17:24 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 9 Apr 2021 15:24:52 +0000 (17:24 +0200)
Problem:    Vim9: a lambda accepts too many arguments at the script level.
Solution:   Do not set uf_varargs in Vim9 script.

src/testdir/test_vim9_func.vim
src/testdir/test_vim9_script.vim
src/userfunc.c
src/version.c

index 730cf40aaa50e2b7a7a26856ac3a7fcd25ada402..b0669fe6515c87b9463ae54b152e6869241c2a8f 100644 (file)
@@ -836,6 +836,11 @@ def Test_call_lambda_args()
       enddef
   END
   CheckDefFailure(lines, 'E1167:')
+
+  lines =<< trim END
+    echo ((a) => a)('aa', 'bb')
+  END
+  CheckDefAndScriptFailure(lines, 'E118:', 1)
 enddef
 
 def FilterWithCond(x: string, Cond: func(string): bool): bool
@@ -2114,7 +2119,7 @@ def Test_list_lambda()
          ->substitute("('", ' ', '')
          ->substitute("')", '', '')
          ->substitute('function\zs', ' ', ''))
-  assert_match('def <lambda>\d\+(_: any, ...): number\n1  return 0\n   enddef', body)
+  assert_match('def <lambda>\d\+(_: any): number\n1  return 0\n   enddef', body)
 enddef
 
 def DoFilterThis(a: string): list<string>
@@ -2363,7 +2368,7 @@ def Test_did_emsg_reset()
       vim9script
       au BufWinLeave * #
       def Func()
-          popup_menu('', {callback: () => popup_create('', {})->popup_close()})
+          popup_menu('', {callback: (a, b) => popup_create('', {})->popup_close()})
           eval [][0]
       enddef
       nno <F3> <cmd>call <sid>Func()<cr>
index cb1592abffb5aae31947dcba5004fdd41879282f..98f40bb8f91033e46fa4e0774671e85711b53953 100644 (file)
@@ -3518,7 +3518,7 @@ func Test_no_redraw_when_restoring_cpo()
       vim9script
       set cpo+=M
       exe 'set rtp^=' .. getcwd() .. '/Xdir'
-      au CmdlineEnter : ++once timer_start(0, () => script#func())
+      au CmdlineEnter : ++once timer_start(0, (_) => script#func())
       setline(1, 'some text')
   END
   call writefile(lines, 'XTest_redraw_cpo')
index af107b0db61c82a8645f2bbaa3093a021c7d5815..81a73e280314717dd06b23ca617317e3e94afde0 100644 (file)
@@ -1263,8 +1263,9 @@ get_lambda_tv(
 #endif
        if (sandbox)
            flags |= FC_SANDBOX;
-       // can be called with more args than uf_args.ga_len
-       fp->uf_varargs = TRUE;
+       // In legacy script a lambda can be called with more args than
+       // uf_args.ga_len.
+       fp->uf_varargs = !in_vim9script();
        fp->uf_flags = flags;
        fp->uf_calls = 0;
        fp->uf_script_ctx = current_sctx;
index 452565c1f246ae5012caa4dc8ce98c58c9658f78..a2bd55869a833dc31d65261162c1154ad87d1d6a 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2739,
 /**/
     2738,
 /**/