Problem: No error for using function() badly.
Solution: Check for passing wrong function name. (Ken Takata)
/* Don't allow hiding a function. When "v" is not NULL we might be
* assigning another function to the same var, the type is checked
* below. */
- if (new_var && function_exists(name))
+ if (new_var && function_exists(name, FALSE))
{
EMSG2(_("E705: Variable name conflicts with existing function: %s"),
name);
}
else if (*p == '*') /* internal or user defined function */
{
- n = function_exists(p + 1);
+ n = function_exists(p + 1, FALSE);
}
else if (*p == ':')
{
EMSG2(_(e_invarg2), s);
/* Don't check an autoload name for existence here. */
else if (use_string && vim_strchr(s, AUTOLOAD_CHAR) == NULL
- && !function_exists(s))
+ && !function_exists(s, TRUE))
EMSG2(_("E700: Unknown function: %s"), s);
else
{
void ex_function(exarg_T *eap);
int eval_fname_script(char_u *p);
int translated_function_exists(char_u *name);
-int function_exists(char_u *name);
+int function_exists(char_u *name, int no_deref);
char_u *get_expanded_name(char_u *name, int check);
void func_dump_profile(FILE *fd);
void prof_child_enter(proftime_T *tm);
call assert_fails("call substitute('xxx', '.', {m -> string(extend(m, ['x']))}, '')", 'E742:')
call assert_fails("call substitute('xxx', '.', {m -> string(remove(m, 1))}, '')", 'E742:')
endfunc
+
+func Test_function_with_funcref()
+ let s:f = function('type')
+ let s:fref = function(s:f)
+ call assert_equal(v:t_string, s:fref('x'))
+ call assert_fails("call function('s:f')", 'E700:')
+endfunc
if (ret == FAIL || **arg != '>')
goto errret;
- /* Set up dictionaries for checking local variables and arguments. */
+ /* Set up a flag for checking local variables and arguments. */
if (evaluate)
eval_lavars_used = &eval_lavars;
* TFN_INT: internal function name OK
* TFN_QUIET: be quiet
* TFN_NO_AUTOLOAD: do not use script autoloading
+ * TFN_NO_DEREF: do not dereference a Funcref
* Advances "pp" to just after the function name (if no error).
*/
static char_u *
if (name == lv.ll_exp_name)
name = NULL;
}
- else
+ else if (!(flags & TFN_NO_DEREF))
{
len = (int)(end - *pp);
name = deref_func_name(*pp, &len, partial, flags & TFN_NO_AUTOLOAD);
start);
goto theend;
}
- if (!skip && !(flags & TFN_QUIET))
+ if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF))
{
char_u *cp = vim_strchr(lv.ll_name, ':');
/*
* Return TRUE if a function "name" exists.
+ * If "no_defef" is TRUE, do not dereference a Funcref.
*/
int
-function_exists(char_u *name)
+function_exists(char_u *name, int no_deref)
{
char_u *nm = name;
char_u *p;
int n = FALSE;
+ int flag;
- p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET|TFN_NO_AUTOLOAD,
- NULL, NULL);
+ flag = TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD;
+ if (no_deref)
+ flag |= TFN_NO_DEREF;
+ p = trans_function_name(&nm, FALSE, flag, NULL, NULL);
nm = skipwhite(nm);
/* Only accept "funcname", "funcname ", "funcname (..." and
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2134,
/**/
2133,
/**/
#define TFN_INT 1 /* internal function name OK */
#define TFN_QUIET 2 /* no error messages */
#define TFN_NO_AUTOLOAD 4 /* do not use script autoloading */
+#define TFN_NO_DEREF 8 /* do not dereference a Funcref */
/* Values for get_lval() flags argument: */
#define GLV_QUIET TFN_QUIET /* no error messages */