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>
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
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 347,
/**/
346,
/**/
{
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)