]> granicus.if.org Git - vim/commitdiff
patch 8.2.3065: Vim9: error when sourcing script twice and reusing function v8.2.3065
authorBram Moolenaar <Bram@vim.org>
Sun, 27 Jun 2021 13:35:40 +0000 (15:35 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 27 Jun 2021 13:35:40 +0000 (15:35 +0200)
Problem:    Vim9: error when sourcing script twice and reusing a function
            name.
Solution:   Check if the function is dead. (closes #8463)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 84bf907cd7b898127a57fb718ba915d8801fd9f8..3ff34a2475d53738eefb4f62e2ace1d2f07dd26d 100644 (file)
@@ -1519,6 +1519,27 @@ def Test_vim9script_reload_noclear()
   delete('XExportReload')
   delfunc g:Values
   unlet g:loadCount
+
+  lines =<< trim END
+      vim9script
+      def Inner()
+      enddef
+  END
+  lines->writefile('XreloadScript.vim')
+  source XreloadScript.vim
+
+  lines =<< trim END
+      vim9script
+      def Outer()
+        def Inner()
+        enddef
+      enddef
+      defcompile
+  END
+  lines->writefile('XreloadScript.vim')
+  source XreloadScript.vim
+
+  delete('XreloadScript.vim')
 enddef
 
 def Test_vim9script_reload_import()
index 12f6648195c1b46a2264677c31fb1fce5b5977f2..d07a3208560cb120b71e5c6da2547c19cd8fe285 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3065,
 /**/
     3064,
 /**/
index 46f543284aee99ea6ed9441f80d90e4f1af7bb51..e746ea9d3d95c6ed0ea8607804c8cab4eb6713e2 100644 (file)
@@ -498,8 +498,9 @@ check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg)
            || (ufunc = find_func_even_dead(p, FALSE, cctx)) != NULL)
     {
        // A local or script-local function can shadow a global function.
-       if (ufunc == NULL || !func_is_global(ufunc)
-               || (p[0] == 'g' && p[1] == ':'))
+       if (ufunc == NULL || ((ufunc->uf_flags & FC_DEAD) == 0
+                   && (!func_is_global(ufunc)
+                                            || (p[0] == 'g' && p[1] == ':'))))
        {
            if (is_arg)
                semsg(_(e_argument_name_shadows_existing_variable_str), p);