[vim/vim] Vim9: crash when a closure assigns to a variable declared in a loop (PR #20881)
h_east (Vim Github Repository) <[email protected]> Wed, 29 Jul 2026 20:00:31 -0700
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/pull/[email protected]> |
```
Problem: Vim9: crash when a closure assigns to a variable that was
declared in a loop (neoharju)
Solution: Encode the loop depth in the STOREOUTER instruction the same way
as in LOADOUTER, so that the executor decodes it correctly.
```
fixes: #20877
---
### Notes
The executor decodes "outer_depth" the same way for ISN_LOADOUTER and
ISN_STOREOUTER, but generate_STOREOUTER() wrote a fixed sentinel instead of
the depth, so a loop variable was looked up in an unused out_loop[] entry
with a NULL stack. A fixed sentinel cannot express the depth at all, so a
closure assigning to a variable of a nested loop could never have worked;
there is a test for that case as well.
The bounds check that the report suggests for the executor is not added.
The index is "-outer_depth - 1", which is the loop depth, and nesting beyond
MAX_LOOP_DEPTH is already rejected at compile time with E1306, so the index
stays within out_loop[].
OUTER_LOOP_DEPTH is removed, it has no user left.
You can view, comment on, or merge this pull request online at:
https://github.com/vim/vim/pull/20881
-- Commit Summary --
* Vim9: crash when a closure assigns to a variable declared in a loop
-- File Changes --
M src/testdir/test_vim9_script.vim (30)
M src/vim9.h (6)
M src/vim9execute.c (7)
M src/vim9instr.c (14)
-- Patch Links --
https://github.com/vim/vim/pull/20881.patch
https://github.com/vim/vim/pull/20881.diff
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/pull/20881
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/pull/[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/pull/20881%40github.com.