Skip to content

Commit b657198

Browse files
committed
patch 8.2.2316: Vim9: cannot list a lambda function
Problem: Vim9: cannot list a lambda function. Solution: Support the <lambda>9 notation, like :disassemble. (closes #7634)
1 parent 832ea89 commit b657198

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/testdir/test_vim9_func.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,16 @@ def Test_line_continuation_in_lambda()
18021802
Line_continuation_in_lambda()->assert_equal(['D', 'C', 'B', 'A'])
18031803
enddef
18041804

1805+
def Test_list_lambda()
1806+
timer_start(1000, (_) => 0)
1807+
var body = execute(timer_info()[0].callback
1808+
->string()
1809+
->substitute("('", ' ', '')
1810+
->substitute("')", '', '')
1811+
->substitute('function\zs', ' ', ''))
1812+
assert_match('def <lambda>\d\+(_: any, ...): number\n1 return 0\n enddef', body)
1813+
enddef
1814+
18051815
func Test_silent_echo()
18061816
CheckScreendump
18071817

src/userfunc.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,15 @@ define_function(exarg_T *eap, char_u *name_arg)
30943094
}
30953095
else
30963096
{
3097-
name = trans_function_name(&p, &is_global, eap->skip,
3097+
if (STRNCMP(p, "<lambda>", 8) == 0)
3098+
{
3099+
p += 8;
3100+
(void)getdigits(&p);
3101+
name = vim_strnsave(eap->arg, p - eap->arg);
3102+
CLEAR_FIELD(fudi);
3103+
}
3104+
else
3105+
name = trans_function_name(&p, &is_global, eap->skip,
30983106
TFN_NO_AUTOLOAD, &fudi, NULL, NULL);
30993107
paren = (vim_strchr(p, '(') != NULL);
31003108
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)

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+
2316,
753755
/**/
754756
2315,
755757
/**/

0 commit comments

Comments
 (0)