patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Problem: Vim9: crash when using variable in a loop at script level.
Solution: Do not clear the variable if a function was defined.
Do not create a new entry in sn_var_vals every time.
(closes #8628)
diff --git a/src/ex_eval.c b/src/ex_eval.c
index 6491955..827f9cd 100644
--- a/src/ex_eval.c
+++ b/src/ex_eval.c
@@ -972,9 +972,6 @@
hide_script_var(si, i, func_defined);
}
- // TODO: is this needed?
- cstack->cs_script_var_len[cstack->cs_idx] = si->sn_var_vals.ga_len;
-
if (cstack->cs_idx == 0)
si->sn_current_block_id = 0;
else
@@ -1178,6 +1175,8 @@
{
scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid);
int i;
+ int func_defined = cstack->cs_flags[cstack->cs_idx]
+ & CSF_FUNC_DEF;
// Any variables defined in the previous round are no longer
// visible.
@@ -1192,10 +1191,8 @@
if (sv->sv_name != NULL)
// Remove a variable declared inside the block, if it
// still exists, from sn_vars.
- hide_script_var(si, i, FALSE);
+ hide_script_var(si, i, func_defined);
}
- cstack->cs_script_var_len[cstack->cs_idx] =
- si->sn_var_vals.ga_len;
}
}
cstack->cs_flags[cstack->cs_idx] =
@@ -1222,14 +1219,7 @@
/*
* ":for var in list-expr"
*/
- CLEAR_FIELD(evalarg);
- evalarg.eval_flags = skip ? 0 : EVAL_EVALUATE;
- if (getline_equal(eap->getline, eap->cookie, getsourceline))
- {
- evalarg.eval_getline = eap->getline;
- evalarg.eval_cookie = eap->cookie;
- }
-
+ fill_evalarg_from_eap(&evalarg, eap, skip);
if ((cstack->cs_lflags & CSL_HAD_LOOP) != 0)
{
// Jumping here from a ":continue" or ":endfor": use the