# HG changeset patch # User Bram Moolenaar # Date 1624801503 -7200 # Node ID ffc3e116465222ff1c3bb6242f7f09cd555c3803 # Parent 43593a5d873f27d1e96a60c5a3421c991f4c05f6 patch 8.2.3065: Vim9: error when sourcing script twice and reusing function Commit: https://github.com/vim/vim/commit/577dc93da9ec78684576bff71328d40f24bd6dd8 Author: Bram Moolenaar Date: Sun Jun 27 15:35:40 2021 +0200 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) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3065, +/**/ 3064, /**/ 3063, diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -498,8 +498,9 @@ check_defined(char_u *p, size_t len, cct || (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);