patch 8.2.2209: Vim9: return type of => lambda not parsed
Problem: Vim9: return type of => lambda not parsed.
Solution: Parse and use the return type.
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 3305bbb..fdc805b 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4118,11 +4118,9 @@
// Recognize <type>
if (**arg == '<' && eval_isnamec1((*arg)[1]))
{
- int called_emsg_before = called_emsg;
-
++*arg;
- want_type = parse_type(arg, cctx->ctx_type_list);
- if (called_emsg != called_emsg_before)
+ want_type = parse_type(arg, cctx->ctx_type_list, TRUE);
+ if (want_type == NULL)
return FAIL;
if (**arg != '>')
@@ -4809,7 +4807,7 @@
* compile "return [expr]"
*/
static char_u *
-compile_return(char_u *arg, int set_return_type, cctx_T *cctx)
+compile_return(char_u *arg, int check_return_type, cctx_T *cctx)
{
char_u *p = arg;
garray_T *stack = &cctx->ctx_type_stack;
@@ -4824,8 +4822,10 @@
if (cctx->ctx_skip != SKIP_YES)
{
stack_type = ((type_T **)stack->ga_data)[stack->ga_len - 1];
- if (set_return_type)
+ if (check_return_type && cctx->ctx_ufunc->uf_ret_type == NULL)
+ {
cctx->ctx_ufunc->uf_ret_type = stack_type;
+ }
else
{
if (cctx->ctx_ufunc->uf_ret_type->tt_type == VAR_VOID
@@ -4843,7 +4843,7 @@
}
else
{
- // "set_return_type" cannot be TRUE, only used for a lambda which
+ // "check_return_type" cannot be TRUE, only used for a lambda which
// always has an argument.
if (cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_VOID
&& cctx->ctx_ufunc->uf_ret_type->tt_type != VAR_UNKNOWN)
@@ -5636,7 +5636,9 @@
goto theend;
}
p = skipwhite(var_end + 1);
- type = parse_type(&p, cctx->ctx_type_list);
+ type = parse_type(&p, cctx->ctx_type_list, TRUE);
+ if (type == NULL)
+ goto theend;
has_type = TRUE;
}
else if (lvar != NULL)
@@ -7417,15 +7419,16 @@
* After ex_function() has collected all the function lines: parse and compile
* the lines into instructions.
* Adds the function to "def_functions".
- * When "set_return_type" is set then set ufunc->uf_ret_type to the type of the
- * return statement (used for lambda).
+ * When "check_return_type" is set then set ufunc->uf_ret_type to the type of
+ * the return statement (used for lambda). When uf_ret_type is already set
+ * then check that it matches.
* "outer_cctx" is set for a nested function.
* This can be used recursively through compile_lambda(), which may reallocate
* "def_functions".
* Returns OK or FAIL.
*/
int
-compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
+compile_def_function(ufunc_T *ufunc, int check_return_type, cctx_T *outer_cctx)
{
char_u *line = NULL;
char_u *p;
@@ -7797,7 +7800,7 @@
goto erret;
case CMD_return:
- line = compile_return(p, set_return_type, &cctx);
+ line = compile_return(p, check_return_type, &cctx);
cctx.ctx_had_return = TRUE;
break;