Problem: Vim9: cannot used loop variable later as lambda argument.
Solution: When not in function context check the current block ID.
(closes #8637)
assert_match('def <lambda>\d\+(_: any): number\n1 return 0\n enddef', body)
enddef
-def Test_lamba_block_variable()
+def Test_lambda_block_variable()
var lines =<< trim END
vim9script
var flist: list<func>
endfor
END
CheckScriptFailure(lines, 'E1001: Variable not found: outloop', 1)
+
+ lines =<< trim END
+ vim9script
+ for i in range(10)
+ var Ref = () => 0
+ endfor
+ assert_equal(0, ((i) => 0)(0))
+ END
+ CheckScriptSuccess(lines)
enddef
def Test_legacy_lambda()
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 3222,
/**/
3221,
/**/
return NULL;
sav = HI2SAV(hi);
- if (sav->sav_block_id == 0 || cctx == NULL)
- // variable defined in the script scope or not in a function.
+ if (sav->sav_block_id == 0)
+ // variable defined in the top script scope is always visible
return sav;
+ if (cctx == NULL)
+ {
+ // Not in a function scope, find variable with block id equal to or
+ // smaller than the current block id.
+ while (sav != NULL)
+ {
+ if (sav->sav_block_id <= si->sn_current_block_id)
+ break;
+ sav = sav->sav_next;
+ }
+ return sav;
+ }
+
// Go over the variables with this name and find one that was visible
// from the function.
ufunc = cctx->ctx_ufunc;