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: cannot refer to prior argument in value of optional argument #8496

Closed
lacygoill opened this issue Jul 1, 2021 · 0 comments
Closed

Comments

@lacygoill
Copy link

Describe the bug

In Vim9 script, we cannot refer to a prior argument in the value of an optional argument.

To Reproduce

Run this shell command:

vim -Nu NONE -S <(cat <<'EOF'
    vim9script
    def Okay(mandatory: any, optional = mandatory)
    enddef
    defcompile
EOF
)

E1001 is raised:

E1001: Variable not found: mandatory

Expected behavior

No error is raised, because it is allowed to refer to a prior argument in the value of an option argument, as documented at :help optional-function-argument:

It is possible for later argument defaults to refer to prior arguments,
but not the other way around. They must be prefixed with "a:", as with all
arguments.

Environment

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

Additional context

Regression introduced in 8.2.2590.


No issue with a legacy function:

vim9script
function Okay(mandatory, optional = a:mandatory)
endfunction
no error

Note that this issue is not about asking to be able to refer to a later argument; that's disallowed in legacy. The issue is about the other way around; referring to a prior argument, which is allowed in legacy.


It would be convenient if it could be made to work again, but if it can't, maybe this limitation should be documented.

chrisbra pushed a commit to chrisbra/vim that referenced this issue Aug 30, 2021
…ment

Problem:    Vim9: default argument expression cannot use previous argument
Solution:   Correct argument index. (closes vim#8496)
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