comparison 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
comparison
equal deleted inserted replaced
20346:cd52b48baba5 20347:0e1dfff4f294
1293 // Always use a new sequence number. 1293 // Always use a new sequence number.
1294 current_sctx.sc_seq = ++last_current_SID_seq; 1294 current_sctx.sc_seq = ++last_current_SID_seq;
1295 if (sid > 0) 1295 if (sid > 0)
1296 { 1296 {
1297 hashtab_T *ht; 1297 hashtab_T *ht;
1298 hashitem_T *hi;
1299 dictitem_T *di;
1300 int todo;
1301 int is_vim9 = si->sn_version == SCRIPT_VERSION_VIM9; 1298 int is_vim9 = si->sn_version == SCRIPT_VERSION_VIM9;
1302 1299
1303 // loading the same script again 1300 // loading the same script again
1304 si->sn_had_command = FALSE; 1301 si->sn_had_command = FALSE;
1305 si->sn_version = 1; 1302 si->sn_version = 1;
1306 current_sctx.sc_sid = sid; 1303 current_sctx.sc_sid = sid;
1307 1304
1308 ht = &SCRIPT_VARS(sid); 1305 ht = &SCRIPT_VARS(sid);
1309 todo = (int)ht->ht_used; 1306 if (is_vim9)
1310 for (hi = ht->ht_array; todo > 0; ++hi) 1307 hashtab_free_contents(ht);
1311 if (!HASHITEM_EMPTY(hi)) 1308 else
1312 { 1309 {
1313 --todo; 1310 int todo = (int)ht->ht_used;
1314 di = HI2DI(hi); 1311 hashitem_T *hi;
1315 di->di_flags |= DI_FLAGS_RELOAD; 1312 dictitem_T *di;
1316 } 1313
1314 for (hi = ht->ht_array; todo > 0; ++hi)
1315 if (!HASHITEM_EMPTY(hi))
1316 {
1317 --todo;
1318 di = HI2DI(hi);
1319 di->di_flags |= DI_FLAGS_RELOAD;
1320 }
1321 }
1317 1322
1318 // old imports are no longer valid 1323 // old imports are no longer valid
1319 free_imports(sid); 1324 free_imports(sid);
1320 1325
1321 // in Vim9 script functions are marked deleted 1326 // in Vim9 script functions are marked deleted