From c4ce36d48698669f81ec90f7c9dc9ab8c362e538 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Fri, 14 Aug 2020 17:08:15 +0200 Subject: 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) --- src/testdir/test_vim9_script.vim | 23 +++++++++++++++++++++++ src/userfunc.c | 4 +++- src/version.c | 2 ++ 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index b462e473d9..2b0a4adf21 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1796,6 +1796,29 @@ def Test_import_compile_error() delete('Ximport.vim') enddef +def Test_func_redefine_error() + let lines = [ + 'vim9script', + 'def Func()', + ' eval [][0]', + 'enddef', + 'Func()', + ] + writefile(lines, 'Xtestscript.vim') + + for count in range(3) + try + source Xtestscript.vim + catch /E684/ + # function name should contain every time + assert_match('E684: list index out of range', v:exception) + assert_match('function \d\+_Func, line 1', v:throwpoint) + endtry + endfor + + delete('Xtestscript.vim') +enddef + def Test_func_overrules_import_fails() let export_lines =<< trim END vim9script diff --git a/src/userfunc.c b/src/userfunc.c index 68287ec600..6c57769929 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -1090,7 +1090,6 @@ func_clear_items(ufunc_T *fp) ga_clear_strings(&(fp->uf_args)); ga_clear_strings(&(fp->uf_def_args)); ga_clear_strings(&(fp->uf_lines)); - VIM_CLEAR(fp->uf_name_exp); VIM_CLEAR(fp->uf_arg_types); VIM_CLEAR(fp->uf_def_arg_idx); VIM_CLEAR(fp->uf_va_name); @@ -1146,7 +1145,10 @@ func_free(ufunc_T *fp, int force) func_remove(fp); if ((fp->uf_flags & FC_DEAD) == 0 || force) + { + VIM_CLEAR(fp->uf_name_exp); vim_free(fp); + } } /* diff --git a/src/version.c b/src/version.c index 415a7cc77a..3ae2c72eab 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1445, /**/ 1444, /**/ -- cgit v1.2.3