Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim9: no proper error for trying to declare optional argument in lambda #8455

Closed
lacygoill opened this issue Jun 26, 2021 · 0 comments
Closed

Comments

@lacygoill
Copy link

Describe the bug

In Vim9 script, a confusing error is given when we try to declare an optional argument in a lambda.

To Reproduce

Run this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    var Ref: func(any, ?any): bool
    Ref = (_, v = 0) => true
EOF
)

E1181 is raised:

E1181: Cannot use an underscore here

Expected behavior

A different error is raised, like this one:

E1234: cannot use "name = value" in lambda

Or this one:

E1234: invalid argument name for lambda

Environment

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

Additional context

The current error message is misleading. We can use an underscore in a lambda:

vim9script
var Ref = (_) => 'no error'
echo Ref('ignore me')
no error

And in a regular function, we can use an optional argument after _:

vim9script
var Ref: func(any, ?any): any
def Func(_, v = 'no error'): any
    return v
enddef
Ref = Func
echo Ref('ignore me')
no error

The issue is simply that the optional_argument = value syntax is not supported in a lambda.


Same issue when we wrongly use the ?type syntax (which is only valid when specifying the type of a funcref; not the type of a lambda's argument):

vim9script
var Ref: func(any, ?any): bool
Ref = (_, ?v) => true
E1181: Cannot use an underscore here
chrisbra pushed a commit to chrisbra/vim that referenced this issue Aug 30, 2021
…rror

Problem:    Vim9: using default value in lambda gives confusing error.
Solution:   Pass "default_args" on the first pass to get the arguments.
            (closes vim#8455)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant