summaryrefslogtreecommitdiffstats
path: root/src/ex_eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-20 14:25:07 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-20 14:25:07 +0200
commit39ca4127a094d8aca6f77c01be4f3fea506d5cb7 (patch)
treec9c076a453569a36b9a7eea90bc06e5898ec8e28 /src/ex_eval.c
parent955347cc7e78352a5d49540573ae958ad45e6386 (diff)
patch 8.2.1870: Vim9: no need to keep all script variablesv8.2.1870
Problem: Vim9: no need to keep all script variables. Solution: Only keep script variables when a function was defined that could use them. Fix freeing static string on exit.
Diffstat (limited to 'src/ex_eval.c')
-rw-r--r--src/ex_eval.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ex_eval.c b/src/ex_eval.c
index 22e83ae34c..3703690315 100644
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -930,16 +930,22 @@ leave_block(cstack_T *cstack)
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
int i;
+ int func_defined =
+ cstack->cs_flags[cstack->cs_idx] & CSF_FUNC_DEF;
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;
+ // sv_name is set to NULL if it was already removed. This happens
+ // when it was defined in an inner block and no functions were
+ // defined there.
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, i);
+ // exists, from sn_vars and move the value into sn_all_vars
+ // if "func_defined" is non-zero.
+ hide_script_var(si, i, func_defined);
}
// TODO: is this needed?