Mercurial > vim
diff src/vim9compile.c @ 25370:d52504ef26ed v8.2.3222
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Commit: https://github.com/vim/vim/commit/3c77b6a1ce1d4a06c60bb9fae7eec2775f547d55
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 25 18:07:00 2021 +0200
patch 8.2.3222: Vim9: cannot used loop variable later as lambda argument
Problem: Vim9: cannot used loop variable later as lambda argument.
Solution: When not in function context check the current block ID.
(closes #8637)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 25 Jul 2021 18:15:02 +0200 |
parents | f874e7095878 |
children | 7124992f26ef |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -355,10 +355,23 @@ find_script_var(char_u *name, size_t len 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;