[vim/vim] vim9: E1001 compiling a lambda nested in a :def that references a script variable declared in an enclosing block — compile_lambda() does not inherit uf_blo ck_ids (Issue #20876)
"Niklas E. O. Harju" (Vim Github Repository) <[email protected]> Wed, 29 Jul 2026 14:47:09 -0700
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/issues/[email protected]> |
neoharju created an issue (vim/vim#20876)
### Steps to reproduce
```vim9script
vim9script
if 1
const c = 42
def F(): number
var G = () => c
return G()
enddef
defcompile
endif
```
→ E1001: Variable not found: c
### Expected behaviour
Two nearly identical cases compile fine, which is what makes this look like a bug rather than intended scoping:
" 1. Same lambda, but the variable is at top-level script scope: OK
```vim9script
vim9script
const c = 42
def F(): number
var G = () => c
return G()
enddef
defcompile
```
" 2. Same block-scoped variable, referenced directly by the :def
" instead of through a nested lambda: OK
```vim9script
vim9script
if 1
const c = 42
def F(): number
return c
enddef
defcompile
endif
```
So a :def can see a block-scoped script variable, and a lambda can see a top-level script variable, but a lambda nested inside that :def cannot
see the block-scoped one.
### Version of Vim
Vim 9.2 (patches 1-804, commit 6f02e5cd7, --with-features=huge), Linux x86_64.
### Environment
suggestion for fix [0002-vim9-lambda-inherit-block-ids.patch](https://github.com/user-attachments/files/30523569/0002-vim9-lambda-inherit-block-ids.patch)
### Logs and stack traces
```shell
```
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/issues/20876
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/issues/[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/20876%40github.com.