Mercurial > vim
diff src/evalvars.c @ 22594:209c7aa56325 v8.2.1845
patch 8.2.1845: Vim9: function defined in a block can't use block variables
Commit: https://github.com/vim/vim/commit/8d739de43b84ef7817b3b5b826d1cbfe7572a62a
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Oct 14 19:39:19 2020 +0200
patch 8.2.1845: Vim9: function defined in a block can't use block variables
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 14 Oct 2020 19:45:04 +0200 |
parents | 86a115a80262 |
children | 2c77ec32deeb |
line wrap: on
line diff
--- a/src/evalvars.c +++ b/src/evalvars.c @@ -2882,7 +2882,7 @@ vars_clear_ext(hashtab_T *ht, int free_v } } 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)