Patch 8.2.3705
Problem:    Cannot pass a lambda name to function() or funcref(). (Yegappan
            Lakshmanan)
Solution:   Handle a lambda name differently.
Files:      src/userfunc.c, src/proto/userfunc.pro, src/evalfunc.c,
            src/testdir/test_expr.vim


*** ../vim-8.2.3704/src/userfunc.c      2021-11-28 22:00:08.152081403 +0000
--- src/userfunc.c      2021-11-30 18:14:57.245534957 +0000
***************
*** 3811,3816 ****
--- 3811,3846 ----
  }
  
  /*
+  * Call trans_function_name(), except that a lambda is returned as-is.
+  * Returns the name in allocated memory.
+  */
+     char_u *
+ save_function_name(
+       char_u      **name,
+       int         *is_global,
+       int         skip,
+       int         flags,
+       funcdict_T  *fudi)
+ {
+     char_u *p = *name;
+     char_u *saved;
+ 
+     if (STRNCMP(p, "<lambda>", 8) == 0)
+     {
+       p += 8;
+       (void)getdigits(&p);
+       saved = vim_strnsave(*name, p - *name);
+       if (fudi != NULL)
+           CLEAR_POINTER(fudi);
+     }
+     else
+       saved = trans_function_name(&p, is_global, skip,
+                                                     flags, fudi, NULL, NULL);
+     *name = p;
+     return saved;
+ }
+ 
+ /*
   * List functions.  When "regmatch" is NULL all of then.
   * Otherwise functions matching "regmatch".
   */
***************
*** 3950,3965 ****
      }
      else
      {
!       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)
        {
--- 3980,3987 ----
      }
      else
      {
!       name = save_function_name(&p, &is_global, eap->skip,
!                                                      TFN_NO_AUTOLOAD, &fudi);
        paren = (vim_strchr(p, '(') != NULL);
        if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
        {
*** ../vim-8.2.3704/src/proto/userfunc.pro      2021-01-06 20:59:35.170021945 
+0000
--- src/proto/userfunc.pro      2021-11-30 18:13:13.889789182 +0000
***************
*** 33,38 ****
--- 33,39 ----
  char_u *printable_func_name(ufunc_T *fp);
  char_u *trans_function_name(char_u **pp, int *is_global, int skip, int flags, 
funcdict_T *fdp, partial_T **partial, type_T **type);
  char_u *untrans_function_name(char_u *name);
+ char_u *save_function_name(char_u **name, int *is_global, int skip, int 
flags, funcdict_T *fudi);
  void list_functions(regmatch_T *regmatch);
  ufunc_T *define_function(exarg_T *eap, char_u *name_arg);
  void ex_function(exarg_T *eap);
*** ../vim-8.2.3704/src/evalfunc.c      2021-11-29 20:39:06.670101630 +0000
--- src/evalfunc.c      2021-11-30 18:05:29.539472341 +0000
***************
*** 3955,3963 ****
      if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref)
      {
        name = s;
!       trans_name = trans_function_name(&name, &is_global, FALSE,
!            TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF,
!                                                            NULL, NULL, NULL);
        if (*name != NUL)
            s = NULL;
      }
--- 3955,3962 ----
      if ((use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL) || is_funcref)
      {
        name = s;
!       trans_name = save_function_name(&name, &is_global, FALSE,
!                  TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD | TFN_NO_DEREF, NULL);
        if (*name != NUL)
            s = NULL;
      }
*** ../vim-8.2.3704/src/testdir/test_expr.vim   2021-11-24 15:32:53.723778915 
+0000
--- src/testdir/test_expr.vim   2021-11-30 18:23:51.008564286 +0000
***************
*** 547,552 ****
--- 547,559 ----
    call assert_fails("call function('foo()')", 'E475:')
    call assert_fails("call function('foo()')", 'foo()')
    call assert_fails("function('')", 'E129:')
+ 
+   let Len = {s -> strlen(s)}
+   call assert_equal(6, Len('foobar'))
+   let name = string(Len)
+   " can evaluate "function('<lambda>99')"
+   call execute('let Ref = ' .. name)
+   call assert_equal(4, Ref('text'))
  endfunc
  
  func Test_funcref()
*** ../vim-8.2.3704/src/version.c       2021-11-30 16:14:44.056582159 +0000
--- src/version.c       2021-11-30 18:15:41.285435335 +0000
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     3705,
  /**/

-- 
ARTHUR: Old woman!
DENNIS: Man!
ARTHUR: Man.  I'm sorry.  Old man, What knight live in that castle over there?
DENNIS: I'm thirty-seven.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211130182535.044AC1C0033%40moolenaar.net.

Raspunde prin e-mail lui