Mercurial > vim
diff src/scriptfile.c @ 20347:0e1dfff4f294 v8.2.0729
patch 8.2.0729: Vim9: When reloading a script variables are not cleared
Commit: https://github.com/vim/vim/commit/89483d40438830fb9e74a5ec6c92d2470b05e4c2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 10 15:24:44 2020 +0200
patch 8.2.0729: Vim9: When reloading a script variables are not cleared
Problem: Vim9: When reloading a script variables are not cleared.
Solution: When sourcing a script again clear all script-local variables.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 10 May 2020 15:30:03 +0200 |
parents | 7587d892c00c |
children | b0242bcc74e7 |
line wrap: on
line diff
--- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -1295,9 +1295,6 @@ do_source( if (sid > 0) { hashtab_T *ht; - hashitem_T *hi; - dictitem_T *di; - int todo; int is_vim9 = si->sn_version == SCRIPT_VERSION_VIM9; // loading the same script again @@ -1306,14 +1303,22 @@ do_source( current_sctx.sc_sid = sid; ht = &SCRIPT_VARS(sid); - todo = (int)ht->ht_used; - for (hi = ht->ht_array; todo > 0; ++hi) - if (!HASHITEM_EMPTY(hi)) - { - --todo; - di = HI2DI(hi); - di->di_flags |= DI_FLAGS_RELOAD; - } + if (is_vim9) + hashtab_free_contents(ht); + else + { + int todo = (int)ht->ht_used; + hashitem_T *hi; + dictitem_T *di; + + for (hi = ht->ht_array; todo > 0; ++hi) + if (!HASHITEM_EMPTY(hi)) + { + --todo; + di = HI2DI(hi); + di->di_flags |= DI_FLAGS_RELOAD; + } + } // old imports are no longer valid free_imports(sid);