]> granicus.if.org Git - vim/commitdiff
patch 8.2.1434: Vim9: crash when lambda uses outer function argument v8.2.1434
authorBram Moolenaar <Bram@vim.org>
Wed, 12 Aug 2020 17:42:01 +0000 (19:42 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 12 Aug 2020 17:42:01 +0000 (19:42 +0200)
Problem:    Vim9: crash when lambda uses outer function argument.
Solution:   Set the flag that the outer context is used.

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

index d6313d363fb1898099be2b7873d8c87745813ecb..795ea752d309ba24e9d78e2e555729ef3030e585 100644 (file)
@@ -1443,6 +1443,16 @@ def LambdaWithComments(): func
         }
 enddef
 
+def LambdaUsingArg(x: number): func
+  return {->
+            # some comment
+            x == 1
+            # some comment
+            ||
+            x == 2
+        }
+enddef
+
 def Test_expr7_lambda()
   let La = { -> 'result'}
   assert_equal('result', La())
@@ -1481,6 +1491,9 @@ def Test_expr7_lambda()
   assert_equal(true, LambdaWithComments()(2))
   assert_equal(false, LambdaWithComments()(3))
 
+  assert_equal(false, LambdaUsingArg(0)())
+  assert_equal(true, LambdaUsingArg(1)())
+
   call CheckDefFailure(["filter([1, 2], {k,v -> 1})"], 'E1069:')
 enddef
 
index e182ea6aa945a56849611f39fbdad52fafa864d7..1100818789ea6f54f997159237fb960ebf8e3a9e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1434,
 /**/
     1433,
 /**/
index 87bb0e2c70619ca79db9b5f9738877c4676d1c02..889a5d5c9c7ca9294ac2b716c27198ee6a903a4b 100644 (file)
@@ -2135,7 +2135,10 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
        if (gen_load)
            res = generate_LOAD(cctx, ISN_LOAD, idx, NULL, type);
        if (gen_load_outer)
+       {
            res = generate_LOAD(cctx, ISN_LOADOUTER, idx, NULL, type);
+           cctx->ctx_outer_used = TRUE;
+       }
     }
 
     *arg = end;