]> granicus.if.org Git - vim/commitdiff
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again v8.2.1445
authorBram Moolenaar <Bram@vim.org>
Fri, 14 Aug 2020 15:08:15 +0000 (17:08 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 14 Aug 2020 15:08:15 +0000 (17:08 +0200)
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
src/userfunc.c
src/version.c

index b462e473d98fba16455039d39a016eaba28f7c0f..2b0a4adf218460e3910c0613d9cbcb30fa0bd7b9 100644 (file)
@@ -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 <SNR> every time
+      assert_match('E684: list index out of range', v:exception)
+      assert_match('function <SNR>\d\+_Func, line 1', v:throwpoint)
+    endtry
+  endfor
+
+  delete('Xtestscript.vim')
+enddef
+
 def Test_func_overrules_import_fails()
   let export_lines =<< trim END
       vim9script
index 68287ec600f46a5dca607961bff8860ffb21341b..6c57769929a5a3f75fc58fd0f12715ca8c107d02 100644 (file)
@@ -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);
+    }
 }
 
 /*
index 415a7cc77a39f48a187ff3a9cc53cd35a9a7f210..3ae2c72eabf876e7cda3397759e582e9211cd124 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1445,
 /**/
     1444,
 /**/