Re: [vim/vim] Vim9 script fails to parse multi-line dictionary inside a lambda (Issue #20693)

h_east (Vim Github Repository) <[email protected]> Wed, 29 Jul 2026 07:43:09 -0700
Newsgroups gmane.editors.vim.devel
Message-ID <vim/vim/issues/20693/[email protected]>
h-east left a comment (vim/vim#20693)

The lambda body is not parsed while it is read.  `get_function_body()` in
`src/userfunc.c` collects the lines one by one and ends the block at the first
line whose first non-blank character is `}`.  In your example that is the line
closing the dictionary, so the block that gets compiled is

```vim
  const d = {
    'foo': {'bar': 'baz'}
```

hence E723.

Doing better would mean tokenizing the contents while the lines are read, that
is a full command and expression parser at that point, since `{` and `}` also
occur in strings, comments, patterns and nested lambdas.  Bram rejected that in
#9352:

> The commands are not parsed, the block simply stops at the first line
> starting with a "}".  [...] Parsing the lines inside the block would require
> rewriting the whole command parsing code, that is infeasible.

Put the `}` of the dictionary after the last item instead:

```vim
timer_start(0, (_) => {
  const d = {
    'foo': {'bar': 'baz'} }
})
```

A lambda block and a command block are read by the same code, so this is not
specific to `:command`.  It is documented at `:help command-block`, and #20872
adds a note at `:help inline-function` as well.

Duplicate of #9352.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/issues/20693#issuecomment-5119296439
You are receiving this because you are subscribed to this thread.

Message ID: <vim/vim/issues/20693/[email protected]>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/20693/5119296439%40github.com.