patch 9.2.1171: Vim9: lambda split over lines gives an internal error

Problem:  In a {} block of :autocmd or :command, a lambda whose
          expression continues on the next lines gives E341 and loops
          forever, or E342 when "|" and a command follow it.
Solution: Stop splitting the lambda into lines at the end of the
          expression.

fixes:  #21453
closes: #21455

Assisted-by: Claude
Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Hirohito Higashi authored and Christian Brabandt committed 2026-10-07 18:11:05 +00:00
1 parent ace29011a1
commit ec130c0fd9
3 files changed
+32 -2

No files matched your search

+28
View File
@@ -4070,6 +4070,34 @@ func Test_autocmd_with_block()
augroup END
endfunc
" Test for a lambda in an :autocmd block with the expression split over lines
func Test_autocmd_block_multiline_lambda()
let lines =<< trim END
vim9script
autocmd CmdlineEnter * {
g:Lambda = () => true ?
'yes' :
'no' | g:after = 'done'
}
doautocmd CmdlineEnter
assert_equal('yes', g:Lambda())
assert_equal('done', g:after)
au! CmdlineEnter
autocmd CmdlineEnter * {
g:Lambda = () => false ?
'yes' :
'no'
}
doautocmd CmdlineEnter
assert_equal('no', g:Lambda())
END
call v9.CheckScriptSuccess(lines)
unlet g:Lambda g:after
au! CmdlineEnter
endfunc
" Test for a backslash line continuation in an :autocmd command
func Test_autocmd_line_continuation()
let lines =<< trim END
+2 -2
View File
@@ -1830,13 +1830,13 @@ get_lambda_tv(
{
// Add more lines, split by line breaks. Thus is used when a
// lambda with { cmds } is encountered.
while (*line_end == '\n')
while (line_end < end && *line_end == '\n')
{
if (ga_grow(&newlines, 1) == FAIL)
goto errret;
start = line_end + 1;
line_end = vim_strchr(start, '\n');
if (line_end == NULL)
if (line_end == NULL || line_end > end)
line_end = end;
((char_u **)(newlines.ga_data))[newlines.ga_len++] =
vim_strnsave(start, line_end - start);
+2
View File
@@ -743,6 +743,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1171,
/**/
1170,
/**/