Mercurial > vim
comparison src/userfunc.c @ 26348:bf1a7ce3f14a v8.2.3705
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Commit: https://github.com/vim/vim/commit/eba3b7f6645c8f856132b4c06a009a3b0a44e21c
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 30 18:25:08 2021 +0000
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Problem: Cannot pass a lambda name to function() or funcref(). (Yegappan
Lakshmanan)
Solution: Handle a lambda name differently.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 30 Nov 2021 19:30:05 +0100 |
parents | 3841da4eac23 |
children | 8aba638e91eb |
comparison
equal
deleted
inserted
replaced
26347:cd04fa8a6d91 | 26348:bf1a7ce3f14a |
---|---|
3809 } | 3809 } |
3810 return NULL; | 3810 return NULL; |
3811 } | 3811 } |
3812 | 3812 |
3813 /* | 3813 /* |
3814 * Call trans_function_name(), except that a lambda is returned as-is. | |
3815 * Returns the name in allocated memory. | |
3816 */ | |
3817 char_u * | |
3818 save_function_name( | |
3819 char_u **name, | |
3820 int *is_global, | |
3821 int skip, | |
3822 int flags, | |
3823 funcdict_T *fudi) | |
3824 { | |
3825 char_u *p = *name; | |
3826 char_u *saved; | |
3827 | |
3828 if (STRNCMP(p, "<lambda>", 8) == 0) | |
3829 { | |
3830 p += 8; | |
3831 (void)getdigits(&p); | |
3832 saved = vim_strnsave(*name, p - *name); | |
3833 if (fudi != NULL) | |
3834 CLEAR_POINTER(fudi); | |
3835 } | |
3836 else | |
3837 saved = trans_function_name(&p, is_global, skip, | |
3838 flags, fudi, NULL, NULL); | |
3839 *name = p; | |
3840 return saved; | |
3841 } | |
3842 | |
3843 /* | |
3814 * List functions. When "regmatch" is NULL all of then. | 3844 * List functions. When "regmatch" is NULL all of then. |
3815 * Otherwise functions matching "regmatch". | 3845 * Otherwise functions matching "regmatch". |
3816 */ | 3846 */ |
3817 void | 3847 void |
3818 list_functions(regmatch_T *regmatch) | 3848 list_functions(regmatch_T *regmatch) |
3948 paren = TRUE; | 3978 paren = TRUE; |
3949 CLEAR_FIELD(fudi); | 3979 CLEAR_FIELD(fudi); |
3950 } | 3980 } |
3951 else | 3981 else |
3952 { | 3982 { |
3953 if (STRNCMP(p, "<lambda>", 8) == 0) | 3983 name = save_function_name(&p, &is_global, eap->skip, |
3954 { | 3984 TFN_NO_AUTOLOAD, &fudi); |
3955 p += 8; | |
3956 (void)getdigits(&p); | |
3957 name = vim_strnsave(eap->arg, p - eap->arg); | |
3958 CLEAR_FIELD(fudi); | |
3959 } | |
3960 else | |
3961 name = trans_function_name(&p, &is_global, eap->skip, | |
3962 TFN_NO_AUTOLOAD, &fudi, NULL, NULL); | |
3963 paren = (vim_strchr(p, '(') != NULL); | 3985 paren = (vim_strchr(p, '(') != NULL); |
3964 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) | 3986 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) |
3965 { | 3987 { |
3966 /* | 3988 /* |
3967 * Return on an invalid expression in braces, unless the expression | 3989 * Return on an invalid expression in braces, unless the expression |