comparison src/vim9compile.c @ 25344:d1fcd9c14a93 v8.2.3209

patch 8.2.3209: Vim9: lambda doesn't find block-local variable Commit: https://github.com/vim/vim/commit/88421d6dc812a2f3b0eab34740f174c9558cb734 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 24 14:14:52 2021 +0200 patch 8.2.3209: Vim9: lambda doesn't find block-local variable Problem: Vim9: lambda doesn't find block-local variable. Solution: Adjust how a script-local variable is found. (closes https://github.com/vim/vim/issues/8614)
author Bram Moolenaar <Bram@vim.org>
date Sat, 24 Jul 2021 14:15:04 +0200
parents 37001467805f
children f874e7095878
comparison
equal deleted inserted replaced
25343:f182fac1243e 25344:d1fcd9c14a93
337 { 337 {
338 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); 338 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
339 hashitem_T *hi; 339 hashitem_T *hi;
340 int cc; 340 int cc;
341 sallvar_T *sav; 341 sallvar_T *sav;
342 sallvar_T *found_sav;
342 ufunc_T *ufunc; 343 ufunc_T *ufunc;
343 344
344 // Find the list of all script variables with the right name. 345 // Find the list of all script variables with the right name.
345 if (len > 0) 346 if (len > 0)
346 { 347 {
359 return sav; 360 return sav;
360 361
361 // Go over the variables with this name and find one that was visible 362 // Go over the variables with this name and find one that was visible
362 // from the function. 363 // from the function.
363 ufunc = cctx->ctx_ufunc; 364 ufunc = cctx->ctx_ufunc;
365 found_sav = sav;
364 while (sav != NULL) 366 while (sav != NULL)
365 { 367 {
366 int idx; 368 int idx;
367 369
368 // Go over the blocks that this function was defined in. If the 370 // Go over the blocks that this function was defined in. If the
371 if (ufunc->uf_block_ids[idx] == sav->sav_block_id) 373 if (ufunc->uf_block_ids[idx] == sav->sav_block_id)
372 return sav; 374 return sav;
373 sav = sav->sav_next; 375 sav = sav->sav_next;
374 } 376 }
375 377
376 return NULL; 378 // Not found, assume variable at script level was visible.
379 return found_sav;
377 } 380 }
378 381
379 /* 382 /*
380 * Return TRUE if the script context is Vim9 script. 383 * Return TRUE if the script context is Vim9 script.
381 */ 384 */