Skip to content

Commit b451856

Browse files
committed
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.
1 parent bdb6579 commit b451856

3 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/testdir/test_lambda.vim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,9 @@ func Test_named_function_closure()
284284
call test_garbagecollect_now()
285285
call assert_equal(14, s:Abar())
286286
endfunc
287+
288+
func Test_lambda_with_index()
289+
let List = {x -> [x]}
290+
let Extract = {-> function(List, ['foobar'])()[0]}
291+
call assert_equal('foobar', Extract())
292+
endfunc

src/userfunc.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,16 @@ call_func(
13491349
}
13501350

13511351

1352-
/* execute the function if no errors detected and executing */
1353-
if (evaluate && error == ERROR_NONE)
1352+
/*
1353+
* Execute the function if executing and no errors were detected.
1354+
*/
1355+
if (!evaluate)
1356+
{
1357+
// Not evaluating, which means the return value is unknown. This
1358+
// matters for giving error messages.
1359+
rettv->v_type = VAR_UNKNOWN;
1360+
}
1361+
else if (error == ERROR_NONE)
13541362
{
13551363
char_u *rfname = fname;
13561364

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
19,
764766
/**/
765767
18,
766768
/**/

0 commit comments

Comments
 (0)