patch 9.2.0347: Vim9: script-local variable not found

Problem:  Vim9: script-local variable not found after function call
          (Mao-Yining)
Solution: Accept a script local variable in a function which overrides a
          previous block-scope variable (Yegappan Lakshmanan)

fixes:  #19959
closes: #19963

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2026-04-14 17:02:21 +00:00
committed by Christian Brabandt
parent c4fe1e958a
commit 39875daec2
3 changed files with 29 additions and 0 deletions
+22
View File
@@ -5759,6 +5759,28 @@ def Test_multikey_dict_in_block()
unlet g:TestDict
enddef
" Test for overriding a block level variable with a new script level variable
" and referring to it in a function.
def Test_block_var_override_with_script_var()
var lines =<< trim END
vim9script
if true
var lines = ['a']
lines->filter((_, _) => true)
endif
var lines = []
def Fx()
lines->add('b')
enddef
Fx()
assert_equal(['b'], lines)
END
v9.CheckSourceSuccess(lines)
enddef
" Test for using the type() function with void
def Test_type_func_with_void()
var lines =<< trim END
+2
View File
@@ -734,6 +734,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
347,
/**/
346,
/**/
+5
View File
@@ -253,6 +253,11 @@ find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
{
int idx;
if (ufunc->uf_block_depth == 0 && sav->sav_block_id == 0)
// If the function was defined at the script level (not inside a
// block), script-scope variables are always visible.
return sav;
// Go over the blocks that this function was defined in. If the
// variable block ID matches it was visible to the function.
for (idx = 0; idx < ufunc->uf_block_depth; ++idx)