diff src/vim9execute.c @ 22527:c3e3c5707fe9 v8.2.1812

patch 8.2.1812: Vim9: nested closure throws an internal error Commit: https://github.com/vim/vim/commit/0876c78527469ddf50c23244566dd5bc35004307 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Oct 7 19:08:04 2020 +0200 patch 8.2.1812: Vim9: nested closure throws an internal error Problem: Vim9: nested closure throws an internal error. Solution: Do not skip a local variable with a partial. (closes https://github.com/vim/vim/issues/7065)
author Bram Moolenaar <Bram@vim.org>
date Wed, 07 Oct 2020 19:15:04 +0200
parents ef8a3177edc1
children 7d6ba4204f66
line wrap: on
line diff
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -377,10 +377,11 @@ handle_closure_in_use(ectx_T *ectx, int 
 	    tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE + idx);
 
 	    // Do not copy a partial created for a local function.
-	    // TODO: this won't work if the closure actually uses it.  But when
+	    // TODO: This won't work if the closure actually uses it.  But when
 	    // keeping it it gets complicated: it will create a reference cycle
 	    // inside the partial, thus needs special handling for garbage
 	    // collection.
+	    // For now, decide on the reference count.
 	    if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL)
 	    {
 		int i;
@@ -389,7 +390,8 @@ handle_closure_in_use(ectx_T *ectx, int 
 		{
 		    partial_T *pt = ((partial_T **)gap->ga_data)[gap->ga_len
 							  - closure_count + i];
-		    if (tv->vval.v_partial == pt)
+
+		    if (tv->vval.v_partial == pt && pt->pt_refcount < 2)
 			break;
 		}
 		if (i < closure_count)