Problem: Confusing error when using name of import for a function.
Solution: Pass a flag to trans_function_name().
// If "s" is the name of a variable of type VAR_FUNC
// use its contents.
s = deref_func_name(s, &len, &partial,
- in_vim9script() ? &type : NULL, !evaluate, &found_var);
+ in_vim9script() ? &type : NULL, !evaluate, FALSE, &found_var);
// Need to make a copy, in case evaluating the arguments makes
// the name invalid.
char_u *get_lambda_name(void);
char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
-char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int *found_var);
+char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int new_function, int *found_var);
void emsg_funcname(char *ermsg, char_u *name);
int get_func_tv(char_u *name, int len, typval_T *rettv, char_u **arg, evalarg_T *evalarg, funcexe_T *funcexe);
char_u *fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error);
END
CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
+ lines =<< trim END
+ vim9script
+ import './Xthat.vim' as That
+ def Func()
+ echo That()
+ enddef
+ Func()
+ END
+ CheckScriptFailure(lines, 'E1236: Cannot use That itself')
+
lines =<< trim END
import './Xthat.vim' as one
import './Xthat.vim' as two
echo 'local to function'
enddef
END
- CheckScriptFailure(lines, 'E1236:')
+ CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
lines =<< trim END
vim9script
* "partialp".
* If "type" is not NULL and a Vim9 script-local variable is found look up the
* type of the variable.
+ * If "new_function" is TRUE the name is for a new function.
* If "found_var" is not NULL and a variable was found set it to TRUE.
*/
char_u *
partial_T **partialp,
type_T **type,
int no_autoload,
+ int new_function,
int *found_var)
{
dictitem_T *v;
if (import != NULL)
{
name[len] = NUL;
- semsg(_(e_cannot_use_str_itself_it_is_imported), name);
+ if (new_function)
+ semsg(_(e_redefining_imported_item_str), name);
+ else
+ semsg(_(e_cannot_use_str_itself_it_is_imported), name);
name[len] = cc;
*lenp = 0;
return (char_u *)""; // just in case
{
len = (int)STRLEN(lv.ll_exp_name);
name = deref_func_name(lv.ll_exp_name, &len, partial, type,
- flags & TFN_NO_AUTOLOAD, NULL);
+ flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
if (name == lv.ll_exp_name)
name = NULL;
}
{
len = (int)(end - *pp);
name = deref_func_name(*pp, &len, partial, type,
- flags & TFN_NO_AUTOLOAD, NULL);
+ flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
if (name == *pp)
name = NULL;
}
else
{
name = save_function_name(&p, &is_global, eap->skip,
- TFN_NO_AUTOLOAD, &fudi);
+ TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi);
paren = (vim_strchr(p, '(') != NULL);
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
{
// from trans_function_name().
len = (int)STRLEN(tofree);
name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial,
- in_vim9script() && type == NULL ? &type : NULL, FALSE, &found_var);
+ in_vim9script() && type == NULL ? &type : NULL,
+ FALSE, FALSE, &found_var);
// Skip white space to allow ":call func ()". Not good, but required for
// backward compatibility.
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 4145,
/**/
4144,
/**/
#define TFN_READ_ONLY 0x10 // will not change the var
#define TFN_NO_DECL 0x20 // only used for GLV_NO_DECL
#define TFN_COMPILING 0x40 // only used for GLV_COMPILING
+#define TFN_NEW_FUNC 0x80 // defining a new function
// Values for get_lval() flags argument:
#define GLV_QUIET TFN_QUIET // no error messages