mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.4657: errors for functions are sometimes hard to read
Problem: Errors for functions are sometimes hard to read. Solution: Use printable_func_name() in more places.
This commit is contained in:
30
src/eval.c
30
src/eval.c
@@ -5296,15 +5296,29 @@ echo_string_core(
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VAR_FUNC:
|
case VAR_FUNC:
|
||||||
if (echo_style)
|
|
||||||
{
|
{
|
||||||
*tofree = NULL;
|
char_u buf[MAX_FUNC_NAME_LEN];
|
||||||
r = tv->vval.v_string;
|
|
||||||
}
|
if (echo_style)
|
||||||
else
|
{
|
||||||
{
|
r = make_ufunc_name_readable(tv->vval.v_string,
|
||||||
*tofree = string_quote(tv->vval.v_string, TRUE);
|
buf, MAX_FUNC_NAME_LEN);
|
||||||
r = *tofree;
|
if (r == buf)
|
||||||
|
{
|
||||||
|
r = vim_strsave(buf);
|
||||||
|
*tofree = r;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
*tofree = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*tofree = string_quote(tv->vval.v_string == NULL ? NULL
|
||||||
|
: make_ufunc_name_readable(
|
||||||
|
tv->vval.v_string, buf, MAX_FUNC_NAME_LEN),
|
||||||
|
TRUE);
|
||||||
|
r = *tofree;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
/* userfunc.c */
|
/* userfunc.c */
|
||||||
void func_init(void);
|
void func_init(void);
|
||||||
hashtab_T *func_tbl_get(void);
|
hashtab_T *func_tbl_get(void);
|
||||||
|
char_u *make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize);
|
||||||
char_u *get_lambda_name(void);
|
char_u *get_lambda_name(void);
|
||||||
char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
|
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);
|
int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
|
||||||
|
@@ -4010,7 +4010,7 @@ func Test_expr_fails()
|
|||||||
call v9.CheckDefFailure(["echo len('asdf'"], 'E110:', 2)
|
call v9.CheckDefFailure(["echo len('asdf'"], 'E110:', 2)
|
||||||
call v9.CheckScriptFailure(['vim9script', "echo len('asdf'"], 'E116:', 2)
|
call v9.CheckScriptFailure(['vim9script', "echo len('asdf'"], 'E116:', 2)
|
||||||
|
|
||||||
call v9.CheckDefAndScriptFailure(["echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], ['E1011:', 'E117:'], 1)
|
call v9.CheckDefAndScriptFailure(["echo Func01234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()"], ['E1011:', 'E117:'], 1)
|
||||||
call v9.CheckDefAndScriptFailure(["echo doesnotexist()"], 'E117:', 1)
|
call v9.CheckDefAndScriptFailure(["echo doesnotexist()"], 'E117:', 1)
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -526,6 +526,28 @@ set_ufunc_name(ufunc_T *fp, char_u *name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough
|
||||||
|
* return "buf" filled with a readable function name.
|
||||||
|
* Otherwise just return "name", thus the return value can always be used.
|
||||||
|
* "name" and "buf" may be equal.
|
||||||
|
*/
|
||||||
|
char_u *
|
||||||
|
make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize)
|
||||||
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (name[0] != K_SPECIAL)
|
||||||
|
return name;
|
||||||
|
len = STRLEN(name);
|
||||||
|
if (len + 3 > bufsize)
|
||||||
|
return name;
|
||||||
|
|
||||||
|
mch_memmove(buf + 5, name + 3, len + 1);
|
||||||
|
mch_memmove(buf, "<SNR>", 5);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get a name for a lambda. Returned in static memory.
|
* Get a name for a lambda. Returned in static memory.
|
||||||
*/
|
*/
|
||||||
@@ -3354,13 +3376,12 @@ user_func_error(int error, char_u *name, funcexe_T *funcexe)
|
|||||||
{
|
{
|
||||||
case FCERR_UNKNOWN:
|
case FCERR_UNKNOWN:
|
||||||
if (funcexe->fe_found_var)
|
if (funcexe->fe_found_var)
|
||||||
semsg(_(e_not_callable_type_str), name);
|
emsg_funcname(e_not_callable_type_str, name);
|
||||||
else
|
else
|
||||||
emsg_funcname(e_unknown_function_str, name);
|
emsg_funcname(e_unknown_function_str, name);
|
||||||
break;
|
break;
|
||||||
case FCERR_NOTMETHOD:
|
case FCERR_NOTMETHOD:
|
||||||
emsg_funcname(
|
emsg_funcname(e_cannot_use_function_as_method_str, name);
|
||||||
N_(e_cannot_use_function_as_method_str), name);
|
|
||||||
break;
|
break;
|
||||||
case FCERR_DELETED:
|
case FCERR_DELETED:
|
||||||
emsg_funcname(e_function_was_deleted_str, name);
|
emsg_funcname(e_function_was_deleted_str, name);
|
||||||
@@ -3372,8 +3393,7 @@ user_func_error(int error, char_u *name, funcexe_T *funcexe)
|
|||||||
emsg_funcname(e_not_enough_arguments_for_function_str, name);
|
emsg_funcname(e_not_enough_arguments_for_function_str, name);
|
||||||
break;
|
break;
|
||||||
case FCERR_SCRIPT:
|
case FCERR_SCRIPT:
|
||||||
emsg_funcname(
|
emsg_funcname(e_using_sid_not_in_script_context_str, name);
|
||||||
e_using_sid_not_in_script_context_str, name);
|
|
||||||
break;
|
break;
|
||||||
case FCERR_DICT:
|
case FCERR_DICT:
|
||||||
emsg_funcname(e_calling_dict_function_without_dictionary_str,
|
emsg_funcname(e_calling_dict_function_without_dictionary_str,
|
||||||
@@ -3613,9 +3633,7 @@ theend:
|
|||||||
* cancelled due to an aborting error, an interrupt, or an exception.
|
* cancelled due to an aborting error, an interrupt, or an exception.
|
||||||
*/
|
*/
|
||||||
if (!aborting())
|
if (!aborting())
|
||||||
{
|
|
||||||
user_func_error(error, (name != NULL) ? name : funcname, funcexe);
|
user_func_error(error, (name != NULL) ? name : funcname, funcexe);
|
||||||
}
|
|
||||||
|
|
||||||
// clear the copies made from the partial
|
// clear the copies made from the partial
|
||||||
while (argv_clear > 0)
|
while (argv_clear > 0)
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4657,
|
||||||
/**/
|
/**/
|
||||||
4656,
|
4656,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -1012,10 +1012,11 @@ call_ufunc(
|
|||||||
if (error != FCERR_UNKNOWN)
|
if (error != FCERR_UNKNOWN)
|
||||||
{
|
{
|
||||||
if (error == FCERR_TOOMANY)
|
if (error == FCERR_TOOMANY)
|
||||||
semsg(_(e_too_many_arguments_for_function_str), ufunc->uf_name);
|
semsg(_(e_too_many_arguments_for_function_str),
|
||||||
|
printable_func_name(ufunc));
|
||||||
else
|
else
|
||||||
semsg(_(e_not_enough_arguments_for_function_str),
|
semsg(_(e_not_enough_arguments_for_function_str),
|
||||||
ufunc->uf_name);
|
printable_func_name(ufunc));
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1047,7 +1048,7 @@ call_ufunc(
|
|||||||
|
|
||||||
if (error != FCERR_NONE)
|
if (error != FCERR_NONE)
|
||||||
{
|
{
|
||||||
user_func_error(error, ufunc->uf_name, &funcexe);
|
user_func_error(error, printable_func_name(ufunc), &funcexe);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (did_emsg > did_emsg_before)
|
if (did_emsg > did_emsg_before)
|
||||||
@@ -1211,7 +1212,7 @@ call_partial(
|
|||||||
if (res == FAIL)
|
if (res == FAIL)
|
||||||
{
|
{
|
||||||
if (called_emsg == called_emsg_before)
|
if (called_emsg == called_emsg_before)
|
||||||
semsg(_(e_unknown_function_str),
|
emsg_funcname(e_unknown_function_str,
|
||||||
name == NULL ? (char_u *)"[unknown]" : name);
|
name == NULL ? (char_u *)"[unknown]" : name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -1570,14 +1571,10 @@ call_eval_func(
|
|||||||
dictitem_T *v;
|
dictitem_T *v;
|
||||||
|
|
||||||
v = find_var(name, NULL, FALSE);
|
v = find_var(name, NULL, FALSE);
|
||||||
if (v == NULL)
|
if (v == NULL || (v->di_tv.v_type != VAR_PARTIAL
|
||||||
|
&& v->di_tv.v_type != VAR_FUNC))
|
||||||
{
|
{
|
||||||
semsg(_(e_unknown_function_str), name);
|
emsg_funcname(e_unknown_function_str, name);
|
||||||
return FAIL;
|
|
||||||
}
|
|
||||||
if (v->di_tv.v_type != VAR_PARTIAL && v->di_tv.v_type != VAR_FUNC)
|
|
||||||
{
|
|
||||||
semsg(_(e_unknown_function_str), name);
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
return call_partial(&v->di_tv, argcount, ectx);
|
return call_partial(&v->di_tv, argcount, ectx);
|
||||||
|
@@ -698,7 +698,7 @@ compile_call(
|
|||||||
char_u *name = *arg;
|
char_u *name = *arg;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
int argcount = argcount_init;
|
int argcount = argcount_init;
|
||||||
char_u namebuf[100];
|
char_u namebuf[MAX_FUNC_NAME_LEN];
|
||||||
char_u fname_buf[FLEN_FIXED + 1];
|
char_u fname_buf[FLEN_FIXED + 1];
|
||||||
char_u *tofree = NULL;
|
char_u *tofree = NULL;
|
||||||
int error = FCERR_NONE;
|
int error = FCERR_NONE;
|
||||||
@@ -818,7 +818,7 @@ compile_call(
|
|||||||
res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
|
res = generate_BCALL(cctx, idx, argcount, argcount_init == 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
semsg(_(e_unknown_function_str), namebuf);
|
emsg_funcname(e_unknown_function_str, namebuf);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -843,7 +843,7 @@ compile_call(
|
|||||||
&& vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL)
|
&& vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL)
|
||||||
{
|
{
|
||||||
// A function name without g: prefix must be found locally.
|
// A function name without g: prefix must be found locally.
|
||||||
semsg(_(e_unknown_function_str), namebuf);
|
emsg_funcname(e_unknown_function_str, namebuf);
|
||||||
goto theend;
|
goto theend;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -874,7 +874,7 @@ compile_call(
|
|||||||
if (has_g_namespace || is_autoload)
|
if (has_g_namespace || is_autoload)
|
||||||
res = generate_UCALL(cctx, name, argcount);
|
res = generate_UCALL(cctx, name, argcount);
|
||||||
else
|
else
|
||||||
semsg(_(e_unknown_function_str), namebuf);
|
emsg_funcname(e_unknown_function_str, namebuf);
|
||||||
|
|
||||||
theend:
|
theend:
|
||||||
vim_free(tofree);
|
vim_free(tofree);
|
||||||
|
@@ -1517,7 +1517,7 @@ generate_CALL(cctx_T *cctx, ufunc_T *ufunc, int pushed_argcount)
|
|||||||
}
|
}
|
||||||
if (ufunc->uf_def_status == UF_COMPILE_ERROR)
|
if (ufunc->uf_def_status == UF_COMPILE_ERROR)
|
||||||
{
|
{
|
||||||
emsg_funcname(_(e_call_to_function_that_failed_to_compile_str),
|
emsg_funcname(e_call_to_function_that_failed_to_compile_str,
|
||||||
ufunc->uf_name);
|
ufunc->uf_name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
@@ -1594,12 +1594,12 @@ generate_PCALL(
|
|||||||
|
|
||||||
if (argcount < type->tt_min_argcount - varargs)
|
if (argcount < type->tt_min_argcount - varargs)
|
||||||
{
|
{
|
||||||
semsg(_(e_not_enough_arguments_for_function_str), name);
|
emsg_funcname(e_not_enough_arguments_for_function_str, name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (!varargs && argcount > type->tt_argcount)
|
if (!varargs && argcount > type->tt_argcount)
|
||||||
{
|
{
|
||||||
semsg(_(e_too_many_arguments_for_function_str), name);
|
emsg_funcname(e_too_many_arguments_for_function_str, name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (type->tt_args != NULL)
|
if (type->tt_args != NULL)
|
||||||
|
@@ -780,12 +780,12 @@ check_argument_types(
|
|||||||
return OK; // just in case
|
return OK; // just in case
|
||||||
if (totcount < type->tt_min_argcount - varargs)
|
if (totcount < type->tt_min_argcount - varargs)
|
||||||
{
|
{
|
||||||
semsg(_(e_not_enough_arguments_for_function_str), name);
|
emsg_funcname(e_not_enough_arguments_for_function_str, name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount)
|
if (!varargs && type->tt_argcount >= 0 && totcount > type->tt_argcount)
|
||||||
{
|
{
|
||||||
semsg(_(e_too_many_arguments_for_function_str), name);
|
emsg_funcname(e_too_many_arguments_for_function_str, name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (type->tt_args == NULL)
|
if (type->tt_args == NULL)
|
||||||
|
Reference in New Issue
Block a user