Skip to content

Commit 0640950

Browse files
committed
patch 8.2.2527: Vim9: lambda return type is not determined at script level
Problem: Vim9: lambda return type is not determined at script level. Solution: Compile the lambda to get the return type. (closes #7843)
1 parent 527ed38 commit 0640950

5 files changed

Lines changed: 21 additions & 4 deletions

File tree

src/eval.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3421,7 +3421,17 @@ eval7(
34213421
*/
34223422
case '(': ret = NOTDONE;
34233423
if (in_vim9script())
3424+
{
34243425
ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
3426+
if (ret == OK && evaluate)
3427+
{
3428+
ufunc_T *ufunc = rettv->vval.v_partial->pt_func;
3429+
3430+
// compile it here to get the return type
3431+
compile_def_function(ufunc,
3432+
TRUE, PROFILING(ufunc), NULL);
3433+
}
3434+
}
34253435
if (ret == NOTDONE)
34263436
{
34273437
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);

src/testdir/test_vim9_assign.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,15 +1108,16 @@ def Test_assign_lambda()
11081108
assert_equal(123, FuncRef_Func())
11091109
var FuncRef_Any: any = () => 123
11101110
assert_equal(123, FuncRef_Any())
1111+
var FuncRef_Number: func(): number = () => 321
1112+
assert_equal(321, FuncRef_Number())
11111113
END
11121114
CheckScriptSuccess(lines)
11131115

11141116
lines =<< trim END
11151117
var Ref: func(number)
11161118
Ref = (j) => !j
11171119
END
1118-
CheckDefFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
1119-
CheckScriptFailure(['vim9script'] + lines, 'E1012: Type mismatch; expected func(number) but got func(any): any')
1120+
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
11201121
enddef
11211122

11221123
def Test_heredoc()

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2527,
753755
/**/
754756
2526,
755757
/**/

src/vim.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,12 @@ typedef struct timeval proftime_T;
17871787
typedef int proftime_T; // dummy for function prototypes
17881788
#endif
17891789

1790+
#ifdef FEAT_PROFILE
1791+
# define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
1792+
#else
1793+
# define PROFILING(ufunc) FALSE
1794+
#endif
1795+
17901796
/*
17911797
* When compiling with 32 bit Perl time_t is 32 bits in the Perl code but 64
17921798
* bits elsewhere. That causes memory corruption. Define time_T and use it

src/vim9.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,9 @@ extern garray_T def_functions;
418418
#define LNUM_VARIABLE_RANGE_ABOVE -888
419419

420420
#ifdef FEAT_PROFILE
421-
# define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
422421
# define INSTRUCTIONS(dfunc) \
423422
((do_profiling == PROF_YES && (dfunc->df_ufunc)->uf_profiling) \
424423
? (dfunc)->df_instr_prof : (dfunc)->df_instr)
425424
#else
426-
# define PROFILING(ufunc) FALSE
427425
# define INSTRUCTIONS(dfunc) ((dfunc)->df_instr)
428426
#endif

0 commit comments

Comments
 (0)