Skip to content

Commit 0346b79

Browse files
committed
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Problem: Vim9: no proper error for lambda missing return type. Solution: Check for this error. (closes #7758)
1 parent e507ff1 commit 0346b79

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/errors.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,3 +349,5 @@ EXTERN char e_cannot_define_autocommands_for_all_events[]
349349
INIT(= N_("E1155: Cannot define autocommands for ALL events"));
350350
EXTERN char e_cannot_change_arglist_recursively[]
351351
INIT(= N_("E1156: Cannot change the argument list recursively"));
352+
EXTERN char e_missing_return_type[]
353+
INIT(= N_("E1157: Missing return type"));

src/testdir/test_vim9_func.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,13 @@ def Test_call_lambda_args()
687687
CheckDefAndScriptFailure(lines, 'E1012:')
688688
enddef
689689

690+
def Test_lambda_return_type()
691+
var lines =<< trim END
692+
var Ref = (): => 123
693+
END
694+
CheckDefAndScriptFailure(lines, 'E1157:', 1)
695+
enddef
696+
690697
def Test_lambda_uses_assigned_var()
691698
CheckDefSuccess([
692699
'var x: any = "aaa"'

src/userfunc.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,11 @@ skip_arrow(
491491
s = skipwhite(s + 1);
492492
*ret_type = s;
493493
s = skip_type(s, TRUE);
494+
if (s == *ret_type)
495+
{
496+
emsg(_(e_missing_return_type));
497+
return NULL;
498+
}
494499
}
495500
bef = s;
496501
s = skipwhite(s);
@@ -543,6 +548,7 @@ get_lambda_tv(
543548
char_u *tofree2 = NULL;
544549
int equal_arrow = **arg == '(';
545550
int white_error = FALSE;
551+
int called_emsg_start = called_emsg;
546552

547553
if (equal_arrow && !in_vim9script())
548554
return NOTDONE;
@@ -560,7 +566,7 @@ get_lambda_tv(
560566
{
561567
if (types_optional)
562568
ga_clear_strings(&argtypes);
563-
return NOTDONE;
569+
return called_emsg == called_emsg_start ? NOTDONE : FAIL;
564570
}
565571

566572
// Parse the arguments for real.

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+
2445,
753755
/**/
754756
2444,
755757
/**/

0 commit comments

Comments
 (0)