Mercurial > vim
comparison src/userfunc.c @ 30333:fc0830246f49 v9.0.0502
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Commit: https://github.com/vim/vim/commit/cc34181f9994d64f8c8fa2f5845eaf0cc963067f
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 19 15:54:34 2022 +0100
patch 9.0.0502: a closure in a nested loop in a :def function does not work
Problem: A closure in a nested loop in a :def function does not work.
Solution: Use an array of loopvars, one per loop level.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 19 Sep 2022 17:00:07 +0200 |
parents | 61a688be1899 |
children | c2ef8f0f8ba1 |
comparison
equal
deleted
inserted
replaced
30332:462d122636b3 | 30333:fc0830246f49 |
---|---|
2451 * Copy already defined function "lambda" to a new function with name "global". | 2451 * Copy already defined function "lambda" to a new function with name "global". |
2452 * This is for when a compiled function defines a global function. | 2452 * This is for when a compiled function defines a global function. |
2453 */ | 2453 */ |
2454 int | 2454 int |
2455 copy_lambda_to_global_func( | 2455 copy_lambda_to_global_func( |
2456 char_u *lambda, | 2456 char_u *lambda, |
2457 char_u *global, | 2457 char_u *global, |
2458 short loop_var_idx, | 2458 loopvarinfo_T *loopvarinfo, |
2459 short loop_var_count, | 2459 ectx_T *ectx) |
2460 ectx_T *ectx) | |
2461 { | 2460 { |
2462 ufunc_T *ufunc = find_func_even_dead(lambda, FFED_IS_GLOBAL); | 2461 ufunc_T *ufunc = find_func_even_dead(lambda, FFED_IS_GLOBAL); |
2463 ufunc_T *fp = NULL; | 2462 ufunc_T *fp = NULL; |
2464 | 2463 |
2465 if (ufunc == NULL) | 2464 if (ufunc == NULL) |
2522 { | 2521 { |
2523 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); | 2522 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
2524 | 2523 |
2525 if (pt == NULL) | 2524 if (pt == NULL) |
2526 goto failed; | 2525 goto failed; |
2527 if (fill_partial_and_closure(pt, ufunc, loop_var_idx, loop_var_count, | 2526 if (fill_partial_and_closure(pt, ufunc, loopvarinfo, ectx) == FAIL) |
2528 ectx) == FAIL) | |
2529 { | 2527 { |
2530 vim_free(pt); | 2528 vim_free(pt); |
2531 goto failed; | 2529 goto failed; |
2532 } | 2530 } |
2533 ufunc->uf_partial = pt; | 2531 ufunc->uf_partial = pt; |
2534 --pt->pt_refcount; // not actually referenced here | |
2535 } | 2532 } |
2536 | 2533 |
2537 return OK; | 2534 return OK; |
2538 | 2535 |
2539 failed: | 2536 failed: |