# HG changeset patch # User Bram Moolenaar # Date 1644256803 -3600 # Node ID ecea41486e8aa2c90f17b80fec3c1a80910c00b9 # Parent 40bf8abda7551264702007ba2a034f1fae478cd4 patch 8.2.4321: Vim9: crash when using a funcref to a closure Commit: https://github.com/vim/vim/commit/92368aad613bca700877ccb1725e1cb5a80dd34a Author: Bram Moolenaar Date: Mon Feb 7 17:50:39 2022 +0000 patch 8.2.4321: Vim9: crash when using a funcref to a closure Problem: Vim9: crash when using a funcref to a closure. Solution: Copy pt_outer to the new partial. (closes https://github.com/vim/vim/issues/9714) diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -4454,6 +4454,9 @@ common_function(typval_T *argvars, typva pt->pt_name = name; func_ref(name); } + + if (arg_pt != NULL) + pt->pt_outer = arg_pt->pt_outer; } rettv->v_type = VAR_PARTIAL; rettv->vval.v_partial = pt; diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -3455,6 +3455,28 @@ def Test_nested_lambda_in_closure() delete('XnestedDone') enddef +def Test_nested_closure_funcref() + var lines =<< trim END + vim9script + def Func() + var n: number + def Nested() + ++n + enddef + Nested() + g:result_one = n + var Ref = function(Nested) + Ref() + g:result_two = n + enddef + Func() + END + v9.CheckScriptSuccess(lines) + assert_equal(1, g:result_one) + assert_equal(2, g:result_two) + unlet g:result_one g:result_two +enddef + def Test_check_func_arg_types() var lines =<< trim END vim9script diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -747,6 +747,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4321, +/**/ 4320, /**/ 4319,