patch 9.0.0495: closure doesn't work properly in nested loop
Problem: Closure doesn't work properly in nested loop.
Solution: Save variables up to the outer loop.
diff --git a/src/vim9execute.c b/src/vim9execute.c
index b625261..22dfaaa 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -2671,7 +2671,7 @@
{
partial_T *pt = ((partial_T **)gap->ga_data)[idx];
- if (pt->pt_refcount > 1)
+ if (pt->pt_refcount > 1 && pt->pt_loopvars == NULL)
{
int refcount = pt->pt_refcount;
int i;
@@ -2727,7 +2727,7 @@
{
partial_T *pt = ((partial_T **)gap->ga_data)[idx];
- if (pt->pt_refcount > 1)
+ if (pt->pt_refcount > 1 && pt->pt_loopvars == NULL)
{
++loopvars->lvs_refcount;
pt->pt_loopvars = loopvars;