[vim/vim] Vim9: no error when declaring too many arguments in lambda passed to "searchpair()" (#8329)

53 views
Skip to first unread message

lacygoill

unread,
Jun 5, 2021, 1:20:14 PM6/5/21
to vim/vim, Subscribed

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

  • Vim version: 8.2 Included patches: 1-2943
  • OS: Ubuntu 20.04.2 LTS
  • Terminal: XTerm(353)

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.

lacygoill

unread,
Jun 5, 2021, 1:31:11 PM6/5/21
to vim/vim, Subscribed

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

Bram Moolenaar

unread,
Jun 5, 2021, 3:43:56 PM6/5/21
to vim/vim, Subscribed

Make sure to put the cursor on a "(", then the skip expression will be evaluated and I get:
E1190: 3 arguments too few

Bram Moolenaar

unread,
Jun 5, 2021, 3:43:57 PM6/5/21
to vim/vim, Subscribed

Closed #8329.

lacygoill

unread,
Jun 5, 2021, 3:54:28 PM6/5/21
to vim/vim, Subscribed

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.

Bram Moolenaar

unread,
Jun 5, 2021, 4:00:17 PM6/5/21
to vim/vim, Subscribed


> Ah yes:
> ```vim
> 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:
> ```vim

> 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.

Yes, this is very similar to issue #8092.

--
Communication is one of the most compli..., eh, well, it's hard.
You know what I mean. Not?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages