Skip to content

Commit c4ce36d

Browse files
committed
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Problem: Vim9: function expanded name is cleared when sourcing a script again. Solution: Only clear the expanded name when deleting the function. (closes #6707)
1 parent bc4c505 commit c4ce36d

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

src/testdir/test_vim9_script.vim

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,29 @@ def Test_import_compile_error()
17961796
delete('Ximport.vim')
17971797
enddef
17981798

1799+
def Test_func_redefine_error()
1800+
let lines = [
1801+
'vim9script',
1802+
'def Func()',
1803+
' eval [][0]',
1804+
'enddef',
1805+
'Func()',
1806+
]
1807+
writefile(lines, 'Xtestscript.vim')
1808+
1809+
for count in range(3)
1810+
try
1811+
source Xtestscript.vim
1812+
catch /E684/
1813+
# function name should contain <SNR> every time
1814+
assert_match('E684: list index out of range', v:exception)
1815+
assert_match('function <SNR>\d\+_Func, line 1', v:throwpoint)
1816+
endtry
1817+
endfor
1818+
1819+
delete('Xtestscript.vim')
1820+
enddef
1821+
17991822
def Test_func_overrules_import_fails()
18001823
let export_lines =<< trim END
18011824
vim9script

src/userfunc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,6 @@ func_clear_items(ufunc_T *fp)
10901090
ga_clear_strings(&(fp->uf_args));
10911091
ga_clear_strings(&(fp->uf_def_args));
10921092
ga_clear_strings(&(fp->uf_lines));
1093-
VIM_CLEAR(fp->uf_name_exp);
10941093
VIM_CLEAR(fp->uf_arg_types);
10951094
VIM_CLEAR(fp->uf_def_arg_idx);
10961095
VIM_CLEAR(fp->uf_va_name);
@@ -1146,7 +1145,10 @@ func_free(ufunc_T *fp, int force)
11461145
func_remove(fp);
11471146

11481147
if ((fp->uf_flags & FC_DEAD) == 0 || force)
1148+
{
1149+
VIM_CLEAR(fp->uf_name_exp);
11491150
vim_free(fp);
1151+
}
11501152
}
11511153

11521154
/*

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+
1445,
757759
/**/
758760
1444,
759761
/**/

0 commit comments

Comments
 (0)