mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
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)
This commit is contained in:
10
src/eval.c
10
src/eval.c
@@ -3421,7 +3421,17 @@ eval7(
|
|||||||
*/
|
*/
|
||||||
case '(': ret = NOTDONE;
|
case '(': ret = NOTDONE;
|
||||||
if (in_vim9script())
|
if (in_vim9script())
|
||||||
|
{
|
||||||
ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
|
ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
|
||||||
|
if (ret == OK && evaluate)
|
||||||
|
{
|
||||||
|
ufunc_T *ufunc = rettv->vval.v_partial->pt_func;
|
||||||
|
|
||||||
|
// compile it here to get the return type
|
||||||
|
compile_def_function(ufunc,
|
||||||
|
TRUE, PROFILING(ufunc), NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (ret == NOTDONE)
|
if (ret == NOTDONE)
|
||||||
{
|
{
|
||||||
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
|
*arg = skipwhite_and_linebreak(*arg + 1, evalarg);
|
||||||
|
@@ -1108,6 +1108,8 @@ def Test_assign_lambda()
|
|||||||
assert_equal(123, FuncRef_Func())
|
assert_equal(123, FuncRef_Func())
|
||||||
var FuncRef_Any: any = () => 123
|
var FuncRef_Any: any = () => 123
|
||||||
assert_equal(123, FuncRef_Any())
|
assert_equal(123, FuncRef_Any())
|
||||||
|
var FuncRef_Number: func(): number = () => 321
|
||||||
|
assert_equal(321, FuncRef_Number())
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
@@ -1115,8 +1117,7 @@ def Test_assign_lambda()
|
|||||||
var Ref: func(number)
|
var Ref: func(number)
|
||||||
Ref = (j) => !j
|
Ref = (j) => !j
|
||||||
END
|
END
|
||||||
CheckDefFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
|
CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(any): bool')
|
||||||
CheckScriptFailure(['vim9script'] + lines, 'E1012: Type mismatch; expected func(number) but got func(any): any')
|
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_heredoc()
|
def Test_heredoc()
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2527,
|
||||||
/**/
|
/**/
|
||||||
2526,
|
2526,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1787,6 +1787,12 @@ typedef struct timeval proftime_T;
|
|||||||
typedef int proftime_T; // dummy for function prototypes
|
typedef int proftime_T; // dummy for function prototypes
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FEAT_PROFILE
|
||||||
|
# define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
|
||||||
|
#else
|
||||||
|
# define PROFILING(ufunc) FALSE
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* When compiling with 32 bit Perl time_t is 32 bits in the Perl code but 64
|
* When compiling with 32 bit Perl time_t is 32 bits in the Perl code but 64
|
||||||
* bits elsewhere. That causes memory corruption. Define time_T and use it
|
* bits elsewhere. That causes memory corruption. Define time_T and use it
|
||||||
|
@@ -418,11 +418,9 @@ extern garray_T def_functions;
|
|||||||
#define LNUM_VARIABLE_RANGE_ABOVE -888
|
#define LNUM_VARIABLE_RANGE_ABOVE -888
|
||||||
|
|
||||||
#ifdef FEAT_PROFILE
|
#ifdef FEAT_PROFILE
|
||||||
# define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
|
|
||||||
# define INSTRUCTIONS(dfunc) \
|
# define INSTRUCTIONS(dfunc) \
|
||||||
((do_profiling == PROF_YES && (dfunc->df_ufunc)->uf_profiling) \
|
((do_profiling == PROF_YES && (dfunc->df_ufunc)->uf_profiling) \
|
||||||
? (dfunc)->df_instr_prof : (dfunc)->df_instr)
|
? (dfunc)->df_instr_prof : (dfunc)->df_instr)
|
||||||
#else
|
#else
|
||||||
# define PROFILING(ufunc) FALSE
|
|
||||||
# define INSTRUCTIONS(dfunc) ((dfunc)->df_instr)
|
# define INSTRUCTIONS(dfunc) ((dfunc)->df_instr)
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user