comparison 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
comparison
equal deleted inserted replaced
22593:a6030e19b08f 22594:209c7aa56325
2880 if (v->di_flags & DI_FLAGS_ALLOC) 2880 if (v->di_flags & DI_FLAGS_ALLOC)
2881 vim_free(v); 2881 vim_free(v);
2882 } 2882 }
2883 } 2883 }
2884 hash_clear(ht); 2884 hash_clear(ht);
2885 ht->ht_used = 0; 2885 hash_init(ht);
2886 } 2886 }
2887 2887
2888 /* 2888 /*
2889 * Delete a variable from hashtab "ht" at item "hi". 2889 * Delete a variable from hashtab "ht" at item "hi".
2890 * Clear the variable value and free the dictitem. 2890 * Clear the variable value and free the dictitem.
3140 } 3140 }
3141 di->di_flags = DI_FLAGS_ALLOC; 3141 di->di_flags = DI_FLAGS_ALLOC;
3142 if (flags & ASSIGN_CONST) 3142 if (flags & ASSIGN_CONST)
3143 di->di_flags |= DI_FLAGS_LOCK; 3143 di->di_flags |= DI_FLAGS_LOCK;
3144 3144
3145 // A Vim9 script-local variable is also added to sn_all_vars and
3146 // sn_var_vals.
3145 if (is_script_local && vim9script) 3147 if (is_script_local && vim9script)
3146 { 3148 add_vim9_script_var(di, tv, type);
3147 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
3148
3149 // Store a pointer to the typval_T, so that it can be found by
3150 // index instead of using a hastab lookup.
3151 if (ga_grow(&si->sn_var_vals, 1) == OK)
3152 {
3153 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
3154 + si->sn_var_vals.ga_len;
3155 sv->sv_name = di->di_key;
3156 sv->sv_tv = &di->di_tv;
3157 if (type == NULL)
3158 sv->sv_type = typval2type(tv, &si->sn_type_list);
3159 else
3160 sv->sv_type = type;
3161 sv->sv_const = (flags & ASSIGN_CONST);
3162 sv->sv_export = is_export;
3163 ++si->sn_var_vals.ga_len;
3164
3165 // let ex_export() know the export worked.
3166 is_export = FALSE;
3167 }
3168 }
3169 } 3149 }
3170 3150
3171 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT) 3151 if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT)
3172 copy_tv(tv, &di->di_tv); 3152 copy_tv(tv, &di->di_tv);
3173 else 3153 else