0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level

Problem:    Vim9: a lambda accepts too many arguments at the script level.
Solution:   Do not set uf_varargs in Vim9 script.
This commit is contained in:
Bram Moolenaar
2021-04-09 17:24:52 +02:00
parent dcae51facc
commit 767034c5b8
4 changed files with 13 additions and 5 deletions

View File

@@ -836,6 +836,11 @@ def Test_call_lambda_args()
enddef enddef
END END
CheckDefFailure(lines, 'E1167:') CheckDefFailure(lines, 'E1167:')
lines =<< trim END
echo ((a) => a)('aa', 'bb')
END
CheckDefAndScriptFailure(lines, 'E118:', 1)
enddef enddef
def FilterWithCond(x: string, Cond: func(string): bool): bool def FilterWithCond(x: string, Cond: func(string): bool): bool
@@ -2114,7 +2119,7 @@ def Test_list_lambda()
->substitute("('", ' ', '') ->substitute("('", ' ', '')
->substitute("')", '', '') ->substitute("')", '', '')
->substitute('function\zs', ' ', '')) ->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 enddef
def DoFilterThis(a: string): list<string> def DoFilterThis(a: string): list<string>
@@ -2363,7 +2368,7 @@ def Test_did_emsg_reset()
vim9script vim9script
au BufWinLeave * # au BufWinLeave * #
def Func() def Func()
popup_menu('', {callback: () => popup_create('', {})->popup_close()}) popup_menu('', {callback: (a, b) => popup_create('', {})->popup_close()})
eval [][0] eval [][0]
enddef enddef
nno <F3> <cmd>call <sid>Func()<cr> nno <F3> <cmd>call <sid>Func()<cr>

View File

@@ -3518,7 +3518,7 @@ func Test_no_redraw_when_restoring_cpo()
vim9script vim9script
set cpo+=M set cpo+=M
exe 'set rtp^=' .. getcwd() .. '/Xdir' 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') setline(1, 'some text')
END END
call writefile(lines, 'XTest_redraw_cpo') call writefile(lines, 'XTest_redraw_cpo')

View File

@@ -1263,8 +1263,9 @@ get_lambda_tv(
#endif #endif
if (sandbox) if (sandbox)
flags |= FC_SANDBOX; flags |= FC_SANDBOX;
// can be called with more args than uf_args.ga_len // In legacy script a lambda can be called with more args than
fp->uf_varargs = TRUE; // uf_args.ga_len.
fp->uf_varargs = !in_vim9script();
fp->uf_flags = flags; fp->uf_flags = flags;
fp->uf_calls = 0; fp->uf_calls = 0;
fp->uf_script_ctx = current_sctx; fp->uf_script_ctx = current_sctx;

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 */
/**/
2739,
/**/ /**/
2738, 2738,
/**/ /**/