diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-10-14 19:39:19 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-10-14 19:39:19 +0200 |
commit | 8d739de43b84ef7817b3b5b826d1cbfe7572a62a (patch) | |
tree | b7aca1586e2b679eec84ef76e4ba451ca8c15669 /src/evalvars.c | |
parent | 3d30af8783bf43fbfece641ec81ad8d2f01b3735 (diff) |
patch 8.2.1845: Vim9: function defined in a block can't use block variablesv8.2.1845
Problem: Vim9: function defined in a block can't use variables defined in
that block.
Solution: First step: Make a second hashtab that holds all script variables,
also block-local ones, with more information.
Diffstat (limited to 'src/evalvars.c')
-rw-r--r-- | src/evalvars.c | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 2455046d93..f3253551f2 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -2882,7 +2882,7 @@ vars_clear_ext(hashtab_T *ht, int free_val) } } hash_clear(ht); - ht->ht_used = 0; + hash_init(ht); } /* @@ -3142,30 +3142,10 @@ set_var_const( if (flags & ASSIGN_CONST) di->di_flags |= DI_FLAGS_LOCK; + // A Vim9 script-local variable is also added to sn_all_vars and + // sn_var_vals. if (is_script_local && vim9script) - { - scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); - - // Store a pointer to the typval_T, so that it can be found by - // index instead of using a hastab lookup. - if (ga_grow(&si->sn_var_vals, 1) == OK) - { - svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) - + si->sn_var_vals.ga_len; - sv->sv_name = di->di_key; - sv->sv_tv = &di->di_tv; - if (type == NULL) - sv->sv_type = typval2type(tv, &si->sn_type_list); - else - sv->sv_type = type; - sv->sv_const = (flags & ASSIGN_CONST); - sv->sv_export = is_export; - ++si->sn_var_vals.ga_len; - - // let ex_export() know the export worked. - is_export = FALSE; - } - } + add_vim9_script_var(di, tv, type); } if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) |