comparison src/vim9compile.c @ 26974:fceb494e22de v8.2.4016

patch 8.2.4016: Vim9: incorrect error for argument that is shadowing var Commit: https://github.com/vim/vim/commit/58493cfae255adec2d5b407593b82d07abcc0975 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 6 12:23:30 2022 +0000 patch 8.2.4016: Vim9: incorrect error for argument that is shadowing var Problem: Vim9: incorrect error for argument that is shadowing var. Solution: Ignore variable that is not in block where the function was defined.
author Bram Moolenaar <Bram@vim.org>
date Thu, 06 Jan 2022 13:30:04 +0100
parents ac75c145f0a9
children 8796f1384750
comparison
equal deleted inserted replaced
26973:3d561592f19b 26974:fceb494e22de
160 { 160 {
161 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); 161 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
162 hashitem_T *hi; 162 hashitem_T *hi;
163 int cc; 163 int cc;
164 sallvar_T *sav; 164 sallvar_T *sav;
165 sallvar_T *found_sav;
166 ufunc_T *ufunc; 165 ufunc_T *ufunc;
167 166
168 // Find the list of all script variables with the right name. 167 // Find the list of all script variables with the right name.
169 if (len > 0) 168 if (len > 0)
170 { 169 {
196 } 195 }
197 196
198 // Go over the variables with this name and find one that was visible 197 // Go over the variables with this name and find one that was visible
199 // from the function. 198 // from the function.
200 ufunc = cctx->ctx_ufunc; 199 ufunc = cctx->ctx_ufunc;
201 found_sav = sav;
202 while (sav != NULL) 200 while (sav != NULL)
203 { 201 {
204 int idx; 202 int idx;
205 203
206 // Go over the blocks that this function was defined in. If the 204 // Go over the blocks that this function was defined in. If the
209 if (ufunc->uf_block_ids[idx] == sav->sav_block_id) 207 if (ufunc->uf_block_ids[idx] == sav->sav_block_id)
210 return sav; 208 return sav;
211 sav = sav->sav_next; 209 sav = sav->sav_next;
212 } 210 }
213 211
214 // Not found, assume variable at script level was visible. 212 // Not found, variable was not visible.
215 return found_sav; 213 return NULL;
216 } 214 }
217 215
218 /* 216 /*
219 * Return TRUE if the script context is Vim9 script. 217 * Return TRUE if the script context is Vim9 script.
220 */ 218 */