patch 9.2.0072: inside_block() uses wrong index in loop

Problem:  inside_block() always checks the flags of the top-most stack
          entry  instead of the current loop index.
Solution: Use the loop index 'i' to check all levels of the condition
          stack (Weixie Cui).

closes: #19524

Signed-off-by: Weixie Cui <cuiweixie@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Weixie Cui
2026-02-27 19:09:34 +00:00
committed by Christian Brabandt
parent c598c4de27
commit 1da9d1381f
3 changed files with 25 additions and 1 deletions
+1 -1
View File
@@ -1602,7 +1602,7 @@ inside_block(exarg_T *eap)
int i;
for (i = 0; i <= cstack->cs_idx; ++i)
if (cstack->cs_flags[cstack->cs_idx] & CSF_BLOCK)
if (cstack->cs_flags[i] & CSF_BLOCK)
return TRUE;
return FALSE;
}
+22
View File
@@ -809,6 +809,28 @@ func Test_usercmd_with_block()
endfunc
" Regression test: inside_block() must check all cstack levels, not just the
" top. A :normal! inside an :if inside a {} block needs newline-based nextcmd
" separation to work; the bug was that only cs_flags[cs_idx] was checked.
func Test_usercmd_block_normal_in_nested_if()
let lines =<< trim END
vim9script
command TestCmd {
if true
normal! Ahello
g:result = 'works'
endif
}
new
TestCmd
bwipe!
END
call v9.CheckScriptSuccess(lines)
call assert_equal('works', g:result)
delcommand TestCmd
unlet! g:result
endfunc
func Test_delcommand_buffer()
command Global echo 'global'
command -buffer OneBuffer echo 'one'
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
72,
/**/
71,
/**/