Skip to content

Commit 577dc93

Browse files
committed
patch 8.2.3065: Vim9: error when sourcing script twice and reusing function
Problem: Vim9: error when sourcing script twice and reusing a function name. Solution: Check if the function is dead. (closes #8463)
1 parent 4d8f476 commit 577dc93

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/testdir/test_vim9_script.vim

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,27 @@ def Test_vim9script_reload_noclear()
15191519
delete('XExportReload')
15201520
delfunc g:Values
15211521
unlet g:loadCount
1522+
1523+
lines =<< trim END
1524+
vim9script
1525+
def Inner()
1526+
enddef
1527+
END
1528+
lines->writefile('XreloadScript.vim')
1529+
source XreloadScript.vim
1530+
1531+
lines =<< trim END
1532+
vim9script
1533+
def Outer()
1534+
def Inner()
1535+
enddef
1536+
enddef
1537+
defcompile
1538+
END
1539+
lines->writefile('XreloadScript.vim')
1540+
source XreloadScript.vim
1541+
1542+
delete('XreloadScript.vim')
15221543
enddef
15231544

15241545
def Test_vim9script_reload_import()

src/version.c

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

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3065,
758760
/**/
759761
3064,
760762
/**/

src/vim9compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,9 @@ check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg)
498498
|| (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL)
499499
{
500500
// A local or script-local function can shadow a global function.
501-
if (ufunc == NULL || !func_is_global(ufunc)
502-
|| (p[0] == 'g' && p[1] == ':'))
501+
if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0
502+
&& (!func_is_global(ufunc)
503+
|| (p[0] == 'g' && p[1] == ':'))))
503504
{
504505
if (is_arg)
505506
semsg(_(e_argument_name_shadows_existing_variable_str), p);

0 commit comments

Comments
 (0)