Skip to content

Commit ad486a0

Browse files
committed
patch 8.2.1352: Vim9: no error for shadowing a script-local function
Problem: Vim9: no error for shadowing a script-local function by a nested function. Solution: Check for script-local function. (closes #6586)
1 parent bcbf413 commit ad486a0

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,20 @@ def Test_nested_global_function()
174174
Outer()
175175
END
176176
CheckScriptFailure(lines, "E122:")
177+
178+
lines =<< trim END
179+
vim9script
180+
def Func()
181+
echo 'script'
182+
enddef
183+
def Outer()
184+
def Func()
185+
echo 'inner'
186+
enddef
187+
enddef
188+
defcompile
189+
END
190+
CheckScriptFailure(lines, "E1073:")
177191
enddef
178192

179193
def Test_global_local_function()

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1352,
757759
/**/
758760
1351,
759761
/**/

src/vim9compile.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,21 @@ lookup_script(char_u *name, size_t len)
291291
int
292292
check_defined(char_u *p, size_t len, cctx_T *cctx)
293293
{
294+
int c = p[len];
295+
296+
p[len] = NUL;
294297
if (lookup_script(p, len) == OK
295298
|| (cctx != NULL
296299
&& (lookup_local(p, len, cctx) != NULL
297300
|| lookup_arg(p, len, NULL, NULL, NULL, cctx) == OK))
298-
|| find_imported(p, len, cctx) != NULL)
301+
|| find_imported(p, len, cctx) != NULL
302+
|| find_func_even_dead(p, FALSE, cctx) != NULL)
299303
{
304+
p[len] = c;
300305
semsg(_(e_already_defined), p);
301306
return FAIL;
302307
}
308+
p[len] = c;
303309
return OK;
304310
}
305311

0 commit comments

Comments
 (0)