Skip to content

Commit f09ff72

Browse files
yegappanchrisbra
authored andcommitted
patch 9.1.1884: :defer an empty lambda causes a crash
Problem: :defer an empty lambda causes a crash (Maxim Kim, after v9.1.1882) Solution: Check for missing arguments (Yegappan Lakshmanan) related: #18641 closes: #18653 Signed-off-by: Yegappan Lakshmanan <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 6be154f commit f09ff72

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/testdir/test_vim9_script.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5343,6 +5343,18 @@ def Test_defer_lambda_func()
53435343
defcompile
53445344
END
53455345
v9.CheckScriptFailure(lines, 'E1028: Compiling :def function failed', 1)
5346+
5347+
# Error: lambda without arguments
5348+
lines =<< trim END
5349+
vim9script
5350+
def Foo()
5351+
defer () => {
5352+
}
5353+
assert_report("shouldn't reach here")
5354+
enddef
5355+
defcompile
5356+
END
5357+
v9.CheckScriptFailure(lines, 'E107: Missing parentheses: ', 1)
53465358
enddef
53475359

53485360
" Test for using an non-existing type in a "for" statement.

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,8 @@ static char *(features[]) =
729729

730730
static int included_patches[] =
731731
{ /* Add new patch number below this line */
732+
/**/
733+
1884,
732734
/**/
733735
1883,
734736
/**/

src/vim9cmds.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2047,7 +2047,12 @@ compile_defer(char_u *arg_start, cctx_T *cctx)
20472047
// a lambda function
20482048
if (compile_lambda(&arg, cctx) != OK)
20492049
return NULL;
2050-
paren = arg;
2050+
paren = vim_strchr(arg, '(');
2051+
if (paren == NULL)
2052+
{
2053+
semsg(_(e_missing_parenthesis_str), arg);
2054+
return NULL;
2055+
}
20512056
}
20522057
else
20532058
{

0 commit comments

Comments
 (0)