diff src/vim9compile.c @ 23332:cdb706d5c43d v8.2.2209

patch 8.2.2209: Vim9: return type of => lambda not parsed Commit: https://github.com/vim/vim/commit/9e68c32563d8c9ffe1ac04ecd4ccd730af66b97c Author: Bram Moolenaar <Bram@vim.org> Date: Fri Dec 25 12:38:04 2020 +0100 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.
author Bram Moolenaar <Bram@vim.org>
date Fri, 25 Dec 2020 12:45:05 +0100
parents e8eb4fd44902
children 4b4f695e9cd1
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -4118,11 +4118,9 @@ compile_expr7t(char_u **arg, cctx_T *cct
     // 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_expr0(char_u **arg,  cctx_T *cct
  * 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 @@ compile_return(char_u *arg, int set_retu
 	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 @@ compile_return(char_u *arg, int set_retu
     }
     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 @@ compile_assignment(char_u *arg, exarg_T 
 		    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 @@ add_def_function(ufunc_T *ufunc)
  * 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 @@ compile_def_function(ufunc_T *ufunc, int
 		    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;