To: vim_dev@googlegroups.com Subject: Patch 8.2.4016 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4016 Problem: Vim9: incorrect error for argument that is shadowing var. Solution: Ignore variable that is not in block where the function was defined. Files: src/vim9compile.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.4015/src/vim9compile.c 2022-01-05 20:24:34.280005633 +0000 --- src/vim9compile.c 2022-01-06 12:20:46.485927225 +0000 *************** *** 162,168 **** hashitem_T *hi; int cc; sallvar_T *sav; - sallvar_T *found_sav; ufunc_T *ufunc; // Find the list of all script variables with the right name. --- 162,167 ---- *************** *** 198,204 **** // Go over the variables with this name and find one that was visible // from the function. ufunc = cctx->ctx_ufunc; - found_sav = sav; while (sav != NULL) { int idx; --- 197,202 ---- *************** *** 211,218 **** sav = sav->sav_next; } ! // Not found, assume variable at script level was visible. ! return found_sav; } /* --- 209,216 ---- sav = sav->sav_next; } ! // Not found, variable was not visible. ! return NULL; } /* *** ../vim-8.2.4015/src/testdir/test_vim9_func.vim 2022-01-05 16:50:36.534031580 +0000 --- src/testdir/test_vim9_func.vim 2022-01-06 12:19:55.749966410 +0000 *************** *** 933,938 **** --- 933,953 ---- delfunc g:Func END CheckScriptSuccess(lines) + + # This does not shadow "i" which is visible only inside the for loop + lines =<< trim END + vim9script + + def Foo(i: number) + echo i + enddef + + for i in range(3) + # Foo() is compiled here + Foo(i) + endfor + END + CheckScriptSuccess(lines) enddef func TakesOneArg(arg) *** ../vim-8.2.4015/src/version.c 2022-01-06 11:43:12.913089957 +0000 --- src/version.c 2022-01-06 12:15:03.170011321 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4016, /**/ -- hundred-and-one symptoms of being an internet addict: 237. You tattoo your email address on your forehead. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///