]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0072: inside_block() uses wrong index in loop v9.2.0072
authorWeixie Cui <cuiweixie@gmail.com>
Fri, 27 Feb 2026 19:09:34 +0000 (19:09 +0000)
committerChristian Brabandt <cb@256bit.org>
Fri, 27 Feb 2026 19:12:00 +0000 (19:12 +0000)
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>
src/ex_eval.c
src/testdir/test_usercommands.vim
src/version.c

index c72744555d2aeaaa6b8534387328c98a7bcd5e69..fa610b72eaa56bfe11392552de19278177f34739 100644 (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;
 }
index a327106bc56ad7554b2f3c2f176b0452f532d9ce..5afd8f12786776c5f44b0699e35679939e7e11ff 100644 (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'
index 4524be1da5adb3d9e9b091e5c1a8fa7bcc7cd472..11467caeaaf5d6a07da83ed22d250eff1623a169 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    72,
 /**/
     71,
 /**/