0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

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.
This commit is contained in:
Bram Moolenaar
2020-10-14 19:39:19 +02:00
parent 3d30af8783
commit 8d739de43b
7 changed files with 209 additions and 61 deletions

View File

@@ -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)