Describe the bug
In Vim9 script, no error is given when we declare too many arguments in a lambda passed to searchpair()
, or searchpairpos()
.
To Reproduce
Run this shell command:
vim -Nu NONE -S <(cat <<'EOF'
vim9script
searchpair('(', '', ')', 'W', (a, b, c) => true)
echo 'no error'
EOF
)
"no error" is printed.
Expected behavior
searchpair()
gives an error because we've declared too many arguments in the lambda passed to searchpair()
:
searchpair('(', '', ')', 'W', (a, b, c) => true)
^-----^
"no error" is not printed because Vim aborts sourcing the script.
Environment
Additional context
Same issue with searchpairpos()
:
vim9script searchpairpos('(', '', ')', 'W', (a, b, c) => true) echo 'no error'
no error
AFAIK, the lambda doesn't receive any argument. Shouldn't Vim complain that the lambda didn't receive enough arguments? Like when we pass a lambda to timer_start()
:
vim9script timer_start(0, (a, b, c) => true)
E119: Not enough arguments for function: <lambda>1
Or to map()
:
vim9script echo range(3)->map((a, b, c) => a + b)
E1190: One argument too few
Or to filter()
:
vim9script echo range(3)->filter((a, b, c) => true)
E1190: One argument too few
Unrelated: To be consistent, maybe timer_start()
should complain with E1190
rather than with E119
.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
It seems that the issue is really specific to searchpair()
and searchpairpos()
, because in addition to timer_start()
, map()
and filter()
, we have substitute()
, sort()
and setqflist()
which also complain when we declare too many arguments in their lambda:
vim9script echo 'some text'->substitute('.*', (a, b, c) => 'replacement', '')
E119: Not enough arguments for function: <lambda>1
vim9script echo [4, 1, 3, 2]->sort((a, b, c) => a == b ? 0 : a > b ? 1 : -1)
E119: Not enough arguments for function: <lambda>1
vim9script def MyQftf(_, _): any return repeat(['test'], 100) enddef def Func() setqflist([], 'r', {lines: v:oldfiles, efm: '%f', quickfixtextfunc: MyQftf}) cw enddef Func()
E119: Not enough arguments for function: <SNR>1_MyQftf
Make sure to put the cursor on a "(", then the skip expression will be evaluated and I get:
E1190: 3 arguments too few
Closed #8329.
Ah yes:
vim9script ' ('->setline(1)
searchpair('(', '', ')', 'W', (a, b, c) => true)
E1190: 3 arguments too few
But it's only when the lambda is used while the cursor is somewhere before a paren that Vim gives the error. There is no error at compile time:
vim9script def Func() ' ('->setline(1)
searchpair('(', '', ')', 'W', (a, b, c) => true)
enddef defcompile
I guess it could, because Vim should know that whatever lambda we pass to searchpair()
, it's not supposed to receive any argument. It might not be important here, but in general I think the sooner the errors are found (i.e. the more errors we get at compile time), the better.