]> granicus.if.org Git - vim/commitdiff
patch 8.2.3775: Vim9: lambda compiled without outer context when debugging v8.2.3775
authorBram Moolenaar <Bram@vim.org>
Fri, 10 Dec 2021 16:55:58 +0000 (16:55 +0000)
committerBram Moolenaar <Bram@vim.org>
Fri, 10 Dec 2021 16:55:58 +0000 (16:55 +0000)
Problem:    Vim9: lambda compiled without outer context when debugging.
Solution:   When compiling a lambda for debugging also compile it without.
            (closes #9302)

src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 4d83a4e8fbf97c58ef4bff40cfd0124855154fde..ccbdc70bc6d6a111d62f2d3ccd79e2795d211bd4 100644 (file)
@@ -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\<CR>")
+  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)
index 79abb50b23d8a6717b00fbe9ee32cba4fb3f3983..9bf1fa27c723db055c4f88b700718c1446a1127e 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3775,
 /**/
     3774,
 /**/
index cde56ac208a47d0f14e62950e08f030627e093f7..a75219e0a2fec68d9921b82189198d2c09a0b9dd 100644 (file)
@@ -3762,12 +3762,15 @@ compile_lambda(char_u **arg, cctx_T *cctx)
        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)
-       compile_def_function(ufunc, FALSE, CT_NONE, cctx);
+           || cctx->ctx_compile_type == CT_PROFILE
 #endif
+       )
+       compile_def_function(ufunc, FALSE, CT_NONE, cctx);
 
     // 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