Mercurial > vim
comparison src/vim9execute.c @ 30318:1358585dde2b v9.0.0495
patch 9.0.0495: closure doesn't work properly in nested loop
Commit: https://github.com/vim/vim/commit/dbbb02bc770646776a04122ff58313d170873e67
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Sep 18 12:00:21 2022 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 18 Sep 2022 13:15:06 +0200 |
parents | 029c59bf78f1 |
children | 7fde373affbf |
comparison
equal
deleted
inserted
replaced
30317:96b5bf36b926 | 30318:1358585dde2b |
---|---|
2669 // Check if any created closure is still being referenced. | 2669 // Check if any created closure is still being referenced. |
2670 for (idx = prev_closure_count; idx < gap->ga_len; ++idx) | 2670 for (idx = prev_closure_count; idx < gap->ga_len; ++idx) |
2671 { | 2671 { |
2672 partial_T *pt = ((partial_T **)gap->ga_data)[idx]; | 2672 partial_T *pt = ((partial_T **)gap->ga_data)[idx]; |
2673 | 2673 |
2674 if (pt->pt_refcount > 1) | 2674 if (pt->pt_refcount > 1 && pt->pt_loopvars == NULL) |
2675 { | 2675 { |
2676 int refcount = pt->pt_refcount; | 2676 int refcount = pt->pt_refcount; |
2677 int i; | 2677 int i; |
2678 | 2678 |
2679 // A Reference in a variable inside the loop doesn't count, it gets | 2679 // A Reference in a variable inside the loop doesn't count, it gets |
2725 | 2725 |
2726 for (idx = prev_closure_count; idx < gap->ga_len; ++idx) | 2726 for (idx = prev_closure_count; idx < gap->ga_len; ++idx) |
2727 { | 2727 { |
2728 partial_T *pt = ((partial_T **)gap->ga_data)[idx]; | 2728 partial_T *pt = ((partial_T **)gap->ga_data)[idx]; |
2729 | 2729 |
2730 if (pt->pt_refcount > 1) | 2730 if (pt->pt_refcount > 1 && pt->pt_loopvars == NULL) |
2731 { | 2731 { |
2732 ++loopvars->lvs_refcount; | 2732 ++loopvars->lvs_refcount; |
2733 pt->pt_loopvars = loopvars; | 2733 pt->pt_loopvars = loopvars; |
2734 | 2734 |
2735 pt->pt_outer.out_loop_stack = &loopvars->lvs_ga; | 2735 pt->pt_outer.out_loop_stack = &loopvars->lvs_ga; |