# HG changeset patch # User Bram Moolenaar # Date 1639155605 -3600 # Node ID cd452f46085eefd035a5b2b4b6c822b4cf5ca77f # Parent f19d8c07777106d535823b0b3d296628e7441c5f patch 8.2.3775: Vim9: lambda compiled without outer context when debugging Commit: https://github.com/vim/vim/commit/9fffef9f3562e05755e4b3c46509b2eeeb623ff7 Author: Bram Moolenaar Date: Fri Dec 10 16:55:58 2021 +0000 patch 8.2.3775: Vim9: lambda compiled without outer context when debugging Problem: Vim9: lambda compiled without outer context when debugging. Solution: When compiling a lambda for debugging also compile it without. (closes #9302) diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -4634,6 +4634,29 @@ def Test_xxx_echoerr_line_number() CheckDefExecAndScriptFailure(lines, 'some error continued', 1) enddef +def Test_debug_with_lambda() + CheckRunVimInTerminal + + var lines =<< trim END + vim9script + def Func() + var n = 0 + echo [0]->filter((_, v) => v == n) + enddef + breakadd func Func + Func() + END + writefile(lines, 'XdebugFunc') + var buf = RunVimInTerminal('-S XdebugFunc', {rows: 6, wait_for_ruler: 0}) + WaitForAssert(() => assert_match('^>', term_getline(buf, 6))) + + term_sendkeys(buf, "cont\") + WaitForAssert(() => assert_match('\[0\]', term_getline(buf, 5))) + + StopVimInTerminal(buf) + delete('XdebugFunc') +enddef + def ProfiledWithLambda() var n = 3 echo [[1, 2], [3, 4]]->filter((_, l) => l[0] == n) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3775, +/**/ 3774, /**/ 3773, diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3762,12 +3762,15 @@ compile_lambda(char_u **arg, cctx_T *cct ufunc->uf_ret_type = &t_unknown; compile_def_function(ufunc, FALSE, cctx->ctx_compile_type, cctx); + // When the outer function is compiled for profiling or debugging, the + // lambda may be called without profiling or debugging. Compile it here in + // the right context. + if (cctx->ctx_compile_type == CT_DEBUG #ifdef FEAT_PROFILE - // When the outer function is compiled for profiling, the lambda may be - // called without profiling. Compile it here in the right context. - if (cctx->ctx_compile_type == CT_PROFILE) + || cctx->ctx_compile_type == CT_PROFILE +#endif + ) compile_def_function(ufunc, FALSE, CT_NONE, cctx); -#endif // The last entry in evalarg.eval_tofree_ga is a copy of the last line and // "*arg" may point into it. Point into the original line to avoid a