changeset 23923:be36288235af v8.2.2504

patch 8.2.2504: Vim9: crash when using an argument from a closure Commit: https://github.com/vim/vim/commit/44ec21c467ddf481b422c787324ea08f375f6942 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Feb 12 21:50:57 2021 +0100 patch 8.2.2504: Vim9: crash when using an argument from a closure Problem: Vim9: crash when using an argument from a closure. Solution: Check if gen_load_outer is NULL. (closes https://github.com/vim/vim/issues/7821)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Feb 2021 22:00:04 +0100
parents dba960dacd31
children 2f0d80c68af1
files src/testdir/test_vim9_func.vim src/version.c src/vim9compile.c
diffstat 3 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1669,6 +1669,18 @@ def Test_closure_using_argument()
 
   unlet g:UseArg
   unlet g:UseVararg
+
+  var lines =<< trim END
+      vim9script
+      def Test(Fun: func(number): number): list<number>
+        return map([1, 2, 3], (_, i) => Fun(i))
+      enddef
+      def Inc(nr: number): number
+        return nr + 2
+      enddef
+      assert_equal([3, 4, 5], Test(Inc))
+  END
+  CheckScriptSuccess(lines)
 enddef
 
 def MakeGetAndAppendRefs()
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2504,
+/**/
     2503,
 /**/
     2502,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -261,7 +261,8 @@ arg_exists(
 	if (arg_exists(name, len, idxp, type, gen_load_outer, cctx->ctx_outer)
 									 == OK)
 	{
-	    ++*gen_load_outer;
+	    if (gen_load_outer != NULL)
+		++*gen_load_outer;
 	    return OK;
 	}
     }