]> granicus.if.org Git - vim/commitdiff
patch 8.2.2316: Vim9: cannot list a lambda function v8.2.2316
authorBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 21:24:19 +0000 (22:24 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 8 Jan 2021 21:24:19 +0000 (22:24 +0100)
Problem:    Vim9: cannot list a lambda function.
Solution:   Support the <lambda>9 notation, like :disassemble. (closes #7634)

src/testdir/test_vim9_func.vim
src/userfunc.c
src/version.c

index fb37401a22de7697f5dc7ffbf554f1a8aea61579..3d4f4c9b74112cd7205831dd026cee4cc68c532a 100644 (file)
@@ -1802,6 +1802,16 @@ def Test_line_continuation_in_lambda()
   Line_continuation_in_lambda()->assert_equal(['D', 'C', 'B', 'A'])
 enddef
 
+def Test_list_lambda()
+  timer_start(1000, (_) => 0)
+  var body = execute(timer_info()[0].callback
+         ->string()
+         ->substitute("('", ' ', '')
+         ->substitute("')", '', '')
+         ->substitute('function\zs', ' ', ''))
+  assert_match('def <lambda>\d\+(_: any, ...): number\n1  return 0\n   enddef', body)
+enddef
+
 func Test_silent_echo()
   CheckScreendump
 
index 1918e541f53b12c5b9837858849d08ec11e0e45c..ded9ef7b0f9d335339fe736355f6b256cc8f6ad1 100644 (file)
@@ -3094,7 +3094,15 @@ define_function(exarg_T *eap, char_u *name_arg)
     }
     else
     {
-       name = trans_function_name(&p, &is_global, eap->skip,
+       if (STRNCMP(p, "<lambda>", 8) == 0)
+       {
+           p += 8;
+           (void)getdigits(&p);
+           name = vim_strnsave(eap->arg, p - eap->arg);
+           CLEAR_FIELD(fudi);
+       }
+       else
+           name = trans_function_name(&p, &is_global, eap->skip,
                                           TFN_NO_AUTOLOAD, &fudi, NULL, NULL);
        paren = (vim_strchr(p, '(') != NULL);
        if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
index 10786659569f452096841660a835850a4e018678..f4cfa2ba0029016cae99fae0accfe2cb786565f8 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2316,
 /**/
     2315,
 /**/