changeset 14002:ade79e3e3b88 v8.1.0019

patch 8.1.0019: error when defining a Lambda with index of a function result commit https://github.com/vim/vim/commit/b4518563c73460150344a57879bf5b22cb8b1c77 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 22 18:31:35 2018 +0200 patch 8.1.0019: error when defining a Lambda with index of a function result Problem: Error when defining a Lambda with index of a function result. Solution: When not evaluating an expression and skipping a function call, set the return value to VAR_UNKNOWN.
author Christian Brabandt <cb@256bit.org>
date Tue, 22 May 2018 18:45:05 +0200
parents 4a78b9913023
children 3965a5a6215e
files src/testdir/test_lambda.vim src/userfunc.c src/version.c
diffstat 3 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/testdir/test_lambda.vim
+++ b/src/testdir/test_lambda.vim
@@ -284,3 +284,9 @@ func Test_named_function_closure()
   call test_garbagecollect_now()
   call assert_equal(14, s:Abar())
 endfunc
+
+func Test_lambda_with_index()
+  let List = {x -> [x]}
+  let Extract = {-> function(List, ['foobar'])()[0]}
+  call assert_equal('foobar', Extract())
+endfunc
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1349,8 +1349,16 @@ call_func(
     }
 
 
-    /* execute the function if no errors detected and executing */
-    if (evaluate && error == ERROR_NONE)
+    /*
+     * Execute the function if executing and no errors were detected.
+     */
+    if (!evaluate)
+    {
+	// Not evaluating, which means the return value is unknown.  This
+	// matters for giving error messages.
+	rettv->v_type = VAR_UNKNOWN;
+    }
+    else if (error == ERROR_NONE)
     {
 	char_u *rfname = fname;
 
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    19,
+/**/
     18,
 /**/
     17,