summaryrefslogtreecommitdiffstats
path: root/src/ex_eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-14 19:39:19 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-14 19:39:19 +0200
commit8d739de43b84ef7817b3b5b826d1cbfe7572a62a (patch)
treeb7aca1586e2b679eec84ef76e4ba451ca8c15669 /src/ex_eval.c
parent3d30af8783bf43fbfece641ec81ad8d2f01b3735 (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/ex_eval.c')
-rw-r--r--src/ex_eval.c42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c
index 57c6178727..baf5de3419 100644
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -914,41 +914,35 @@ enter_block(cstack_T *cstack)
{
++cstack->cs_idx;
if (in_vim9script())
- cstack->cs_script_var_len[cstack->cs_idx] =
- SCRIPT_ITEM(current_sctx.sc_sid)->sn_var_vals.ga_len;
+ {
+ scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
+
+ cstack->cs_script_var_len[cstack->cs_idx] = si->sn_var_vals.ga_len;
+ cstack->cs_block_id[cstack->cs_idx] = ++si->sn_current_block_id;
+ }
}
static void
leave_block(cstack_T *cstack)
{
- int i;
-
- if (in_vim9script())
+ if (in_vim9script() && SCRIPT_ID_VALID(current_sctx.sc_sid))
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
- hashtab_T *ht = get_script_local_ht();
+ int i;
- if (ht != NULL)
- {
- for (i = cstack->cs_script_var_len[cstack->cs_idx];
+ for (i = cstack->cs_script_var_len[cstack->cs_idx];
i < si->sn_var_vals.ga_len; ++i)
- {
- svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
- hashitem_T *hi;
+ {
+ svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data) + i;
- if (sv->sv_name != NULL)
- {
- // Remove a variable declared inside the block, if it still
- // exists.
- hi = hash_find(ht, sv->sv_name);
- if (!HASHITEM_EMPTY(hi))
- {
- delete_var(ht, hi);
- sv->sv_name = NULL;
- }
- }
- }
+ if (sv->sv_name != NULL)
+ // Remove a variable declared inside the block, if it still
+ // exists, from sn_vars and move the value into sn_all_vars.
+ hide_script_var(si, sv);
}
+
+ // TODO: is this needed?
+ cstack->cs_script_var_len[cstack->cs_idx] = si->sn_var_vals.ga_len;
}
--cstack->cs_idx;
}