mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
patch 8.2.2308: Vim9: no error when assigning lambda to funcref
Problem: Vim9: no error when assigning lambda to funcref without return value. Solution: Default return value to "any". (closes #7629)
This commit is contained in:
parent
ebbf11c119
commit
328eac2b5d
@ -1091,6 +1091,13 @@ def Test_assign_lambda()
|
|||||||
assert_equal(123, FuncRef_Any())
|
assert_equal(123, FuncRef_Any())
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var Ref: func(number)
|
||||||
|
Ref = (j) => !j
|
||||||
|
END
|
||||||
|
CheckDefFailure(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()
|
||||||
|
@ -1508,7 +1508,7 @@ def Test_unknown_function()
|
|||||||
'delfunc g:NotExist'], 'E700:')
|
'delfunc g:NotExist'], 'E700:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def RefFunc(Ref: func(string): string): string
|
def RefFunc(Ref: func(any): any): string
|
||||||
return Ref('more')
|
return Ref('more')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
@ -668,7 +668,7 @@ get_lambda_tv(
|
|||||||
goto errret;
|
goto errret;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
fp->uf_ret_type = &t_unknown;
|
fp->uf_ret_type = &t_any;
|
||||||
}
|
}
|
||||||
|
|
||||||
fp->uf_lines = newlines;
|
fp->uf_lines = newlines;
|
||||||
|
@ -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 */
|
||||||
|
/**/
|
||||||
|
2308,
|
||||||
/**/
|
/**/
|
||||||
2307,
|
2307,
|
||||||
/**/
|
/**/
|
||||||
|
@ -857,7 +857,9 @@ use_typecheck(type_T *actual, type_T *expected)
|
|||||||
|| (actual->tt_type == VAR_FUNC
|
|| (actual->tt_type == VAR_FUNC
|
||||||
&& (expected->tt_type == VAR_FUNC
|
&& (expected->tt_type == VAR_FUNC
|
||||||
|| expected->tt_type == VAR_PARTIAL)
|
|| expected->tt_type == VAR_PARTIAL)
|
||||||
&& (actual->tt_member == &t_any || actual->tt_argcount < 0)))
|
&& (actual->tt_member == &t_any || actual->tt_argcount < 0)
|
||||||
|
&& ((actual->tt_member == &t_void)
|
||||||
|
== (expected->tt_member == &t_void))))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
|
if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT)
|
||||||
&& actual->tt_type == expected->tt_type)
|
&& actual->tt_type == expected->tt_type)
|
||||||
@ -4812,7 +4814,8 @@ compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
|
|||||||
{
|
{
|
||||||
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
if (check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
|
if (check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
|
||||||
|| cctx->ctx_ufunc->uf_ret_type == &t_unknown))
|
|| cctx->ctx_ufunc->uf_ret_type == &t_unknown
|
||||||
|
|| cctx->ctx_ufunc->uf_ret_type == &t_any))
|
||||||
{
|
{
|
||||||
cctx->ctx_ufunc->uf_ret_type = stack_type;
|
cctx->ctx_ufunc->uf_ret_type = stack_type;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user