mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.1551: Vim9: error for argument type does not mention the number
Problem: Vim9: error for argument type does not mention the number. Solution: Pass the argument number to where the error is given.
This commit is contained in:
@@ -1291,7 +1291,7 @@ set_var_lval(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (lp->ll_type != NULL
|
if (lp->ll_type != NULL
|
||||||
&& check_typval_type(lp->ll_type, rettv) == FAIL)
|
&& check_typval_type(lp->ll_type, rettv, 0) == FAIL)
|
||||||
return;
|
return;
|
||||||
set_var_const(lp->ll_name, lp->ll_type, rettv, copy, flags);
|
set_var_const(lp->ll_name, lp->ll_type, rettv, copy, flags);
|
||||||
}
|
}
|
||||||
|
@@ -7,10 +7,10 @@ type_T *get_func_type(type_T *ret_type, int argcount, garray_T *type_gap);
|
|||||||
int func_type_add_arg_types(type_T *functype, int argcount, garray_T *type_gap);
|
int func_type_add_arg_types(type_T *functype, int argcount, garray_T *type_gap);
|
||||||
type_T *typval2type(typval_T *tv, garray_T *type_gap);
|
type_T *typval2type(typval_T *tv, garray_T *type_gap);
|
||||||
type_T *typval2type_vimvar(typval_T *tv, garray_T *type_gap);
|
type_T *typval2type_vimvar(typval_T *tv, garray_T *type_gap);
|
||||||
int check_typval_type(type_T *expected, typval_T *actual_tv);
|
int check_typval_type(type_T *expected, typval_T *actual_tv, int argidx);
|
||||||
void type_mismatch(type_T *expected, type_T *actual);
|
void type_mismatch(type_T *expected, type_T *actual);
|
||||||
void arg_type_mismatch(type_T *expected, type_T *actual, int argidx);
|
void arg_type_mismatch(type_T *expected, type_T *actual, int argidx);
|
||||||
int check_type(type_T *expected, type_T *actual, int give_msg);
|
int check_type(type_T *expected, type_T *actual, int give_msg, int argidx);
|
||||||
char_u *skip_type(char_u *start, int optional);
|
char_u *skip_type(char_u *start, int optional);
|
||||||
type_T *parse_type(char_u **arg, garray_T *type_gap);
|
type_T *parse_type(char_u **arg, garray_T *type_gap);
|
||||||
void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap);
|
void common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap);
|
||||||
|
@@ -231,7 +231,7 @@ def Test_call_wrong_args()
|
|||||||
enddef
|
enddef
|
||||||
Func([])
|
Func([])
|
||||||
END
|
END
|
||||||
call CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got list<unknown>', 5)
|
call CheckScriptFailure(lines, 'E1013: argument 1: type mismatch, expected string but got list<unknown>', 5)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
" Default arg and varargs
|
" Default arg and varargs
|
||||||
@@ -278,7 +278,7 @@ def Test_call_def_varargs()
|
|||||||
enddef
|
enddef
|
||||||
Func(1, 2, 3)
|
Func(1, 2, 3)
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012:')
|
CheckScriptFailure(lines, 'E1013: argument 1: type mismatch')
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@@ -287,7 +287,7 @@ def Test_call_def_varargs()
|
|||||||
enddef
|
enddef
|
||||||
Func('a', 9)
|
Func('a', 9)
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012:')
|
CheckScriptFailure(lines, 'E1013: argument 2: type mismatch')
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
@@ -296,7 +296,7 @@ def Test_call_def_varargs()
|
|||||||
enddef
|
enddef
|
||||||
Func(1, 'a')
|
Func(1, 'a')
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012:')
|
CheckScriptFailure(lines, 'E1013: argument 1: type mismatch')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_call_call()
|
def Test_call_call()
|
||||||
@@ -691,7 +691,7 @@ def Test_vim9script_call_fail_type()
|
|||||||
enddef
|
enddef
|
||||||
MyFunc(1234)
|
MyFunc(1234)
|
||||||
END
|
END
|
||||||
CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got number')
|
CheckScriptFailure(lines, 'E1013: argument 1: type mismatch, expected string but got number')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_vim9script_call_fail_const()
|
def Test_vim9script_call_fail_const()
|
||||||
|
@@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1551,
|
||||||
/**/
|
/**/
|
||||||
1550,
|
1550,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -729,7 +729,7 @@ need_type(
|
|||||||
cctx_T *cctx,
|
cctx_T *cctx,
|
||||||
int silent)
|
int silent)
|
||||||
{
|
{
|
||||||
if (check_type(expected, actual, FALSE) == OK)
|
if (check_type(expected, actual, FALSE, 0) == OK)
|
||||||
return OK;
|
return OK;
|
||||||
if (actual->tt_type != VAR_ANY
|
if (actual->tt_type != VAR_ANY
|
||||||
&& actual->tt_type != VAR_UNKNOWN
|
&& actual->tt_type != VAR_UNKNOWN
|
||||||
@@ -3581,7 +3581,7 @@ compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
|
|||||||
|
|
||||||
generate_ppconst(cctx, ppconst);
|
generate_ppconst(cctx, ppconst);
|
||||||
actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
if (check_type(want_type, actual, FALSE) == FAIL)
|
if (check_type(want_type, actual, FALSE, 0) == FAIL)
|
||||||
{
|
{
|
||||||
if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
|
if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -6500,13 +6500,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
|
|||||||
did_set_arg_type = TRUE;
|
did_set_arg_type = TRUE;
|
||||||
ufunc->uf_arg_types[arg_idx] = val_type;
|
ufunc->uf_arg_types[arg_idx] = val_type;
|
||||||
}
|
}
|
||||||
else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, FALSE)
|
else if (check_type(ufunc->uf_arg_types[arg_idx], val_type,
|
||||||
== FAIL)
|
TRUE, arg_idx + 1) == FAIL)
|
||||||
{
|
|
||||||
arg_type_mismatch(ufunc->uf_arg_types[arg_idx], val_type,
|
|
||||||
arg_idx + 1);
|
|
||||||
goto erret;
|
goto erret;
|
||||||
}
|
|
||||||
|
|
||||||
if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL)
|
if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL)
|
||||||
goto erret;
|
goto erret;
|
||||||
|
@@ -792,8 +792,8 @@ call_def_function(
|
|||||||
for (idx = 0; idx < argc; ++idx)
|
for (idx = 0; idx < argc; ++idx)
|
||||||
{
|
{
|
||||||
if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len
|
if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len
|
||||||
&& check_typval_type(ufunc->uf_arg_types[idx], &argv[idx])
|
&& check_typval_type(ufunc->uf_arg_types[idx], &argv[idx],
|
||||||
== FAIL)
|
idx + 1) == FAIL)
|
||||||
goto failed_early;
|
goto failed_early;
|
||||||
copy_tv(&argv[idx], STACK_TV_BOT(0));
|
copy_tv(&argv[idx], STACK_TV_BOT(0));
|
||||||
++ectx.ec_stack.ga_len;
|
++ectx.ec_stack.ga_len;
|
||||||
@@ -822,7 +822,8 @@ call_def_function(
|
|||||||
|
|
||||||
for (idx = 0; idx < vararg_count; ++idx)
|
for (idx = 0; idx < vararg_count; ++idx)
|
||||||
{
|
{
|
||||||
if (check_typval_type(expected, &li->li_tv) == FAIL)
|
if (check_typval_type(expected, &li->li_tv,
|
||||||
|
argc + idx + 1) == FAIL)
|
||||||
goto failed_early;
|
goto failed_early;
|
||||||
li = li->li_next;
|
li = li->li_next;
|
||||||
}
|
}
|
||||||
|
@@ -580,7 +580,7 @@ check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
|
|||||||
semsg(_(e_readonlyvar), name);
|
semsg(_(e_readonlyvar), name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
return check_typval_type(sv->sv_type, value);
|
return check_typval_type(sv->sv_type, value, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iemsg("check_script_var_type(): not found");
|
iemsg("check_script_var_type(): not found");
|
||||||
|
@@ -304,7 +304,7 @@ typval2type_vimvar(typval_T *tv, garray_T *type_gap)
|
|||||||
* Return FAIL if "expected" and "actual" don't match.
|
* Return FAIL if "expected" and "actual" don't match.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
check_typval_type(type_T *expected, typval_T *actual_tv)
|
check_typval_type(type_T *expected, typval_T *actual_tv, int argidx)
|
||||||
{
|
{
|
||||||
garray_T type_list;
|
garray_T type_list;
|
||||||
type_T *actual_type;
|
type_T *actual_type;
|
||||||
@@ -313,7 +313,7 @@ check_typval_type(type_T *expected, typval_T *actual_tv)
|
|||||||
ga_init2(&type_list, sizeof(type_T *), 10);
|
ga_init2(&type_list, sizeof(type_T *), 10);
|
||||||
actual_type = typval2type(actual_tv, &type_list);
|
actual_type = typval2type(actual_tv, &type_list);
|
||||||
if (actual_type != NULL)
|
if (actual_type != NULL)
|
||||||
res = check_type(expected, actual_type, TRUE);
|
res = check_type(expected, actual_type, TRUE, argidx);
|
||||||
clear_type_list(&type_list);
|
clear_type_list(&type_list);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -321,22 +321,22 @@ check_typval_type(type_T *expected, typval_T *actual_tv)
|
|||||||
void
|
void
|
||||||
type_mismatch(type_T *expected, type_T *actual)
|
type_mismatch(type_T *expected, type_T *actual)
|
||||||
{
|
{
|
||||||
char *tofree1, *tofree2;
|
arg_type_mismatch(expected, actual, 0);
|
||||||
|
|
||||||
semsg(_(e_type_mismatch_expected_str_but_got_str),
|
|
||||||
type_name(expected, &tofree1), type_name(actual, &tofree2));
|
|
||||||
vim_free(tofree1);
|
|
||||||
vim_free(tofree2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
arg_type_mismatch(type_T *expected, type_T *actual, int argidx)
|
arg_type_mismatch(type_T *expected, type_T *actual, int argidx)
|
||||||
{
|
{
|
||||||
char *tofree1, *tofree2;
|
char *tofree1, *tofree2;
|
||||||
|
char *typename1 = type_name(expected, &tofree1);
|
||||||
|
char *typename2 = type_name(actual, &tofree2);
|
||||||
|
|
||||||
semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str),
|
if (argidx > 0)
|
||||||
argidx,
|
semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str),
|
||||||
type_name(expected, &tofree1), type_name(actual, &tofree2));
|
argidx, typename1, typename2);
|
||||||
|
else
|
||||||
|
semsg(_(e_type_mismatch_expected_str_but_got_str),
|
||||||
|
typename1, typename2);
|
||||||
vim_free(tofree1);
|
vim_free(tofree1);
|
||||||
vim_free(tofree2);
|
vim_free(tofree2);
|
||||||
}
|
}
|
||||||
@@ -344,9 +344,10 @@ arg_type_mismatch(type_T *expected, type_T *actual, int argidx)
|
|||||||
/*
|
/*
|
||||||
* Check if the expected and actual types match.
|
* Check if the expected and actual types match.
|
||||||
* Does not allow for assigning "any" to a specific type.
|
* Does not allow for assigning "any" to a specific type.
|
||||||
|
* When "argidx" > 0 it is included in the error message.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
check_type(type_T *expected, type_T *actual, int give_msg)
|
check_type(type_T *expected, type_T *actual, int give_msg, int argidx)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
|
||||||
@@ -359,19 +360,21 @@ check_type(type_T *expected, type_T *actual, int give_msg)
|
|||||||
if (expected->tt_type != actual->tt_type)
|
if (expected->tt_type != actual->tt_type)
|
||||||
{
|
{
|
||||||
if (give_msg)
|
if (give_msg)
|
||||||
type_mismatch(expected, actual);
|
arg_type_mismatch(expected, actual, argidx);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
|
if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
|
||||||
{
|
{
|
||||||
// "unknown" is used for an empty list or dict
|
// "unknown" is used for an empty list or dict
|
||||||
if (actual->tt_member != &t_unknown)
|
if (actual->tt_member != &t_unknown)
|
||||||
ret = check_type(expected->tt_member, actual->tt_member, FALSE);
|
ret = check_type(expected->tt_member, actual->tt_member,
|
||||||
|
FALSE, 0);
|
||||||
}
|
}
|
||||||
else if (expected->tt_type == VAR_FUNC)
|
else if (expected->tt_type == VAR_FUNC)
|
||||||
{
|
{
|
||||||
if (expected->tt_member != &t_unknown)
|
if (expected->tt_member != &t_unknown)
|
||||||
ret = check_type(expected->tt_member, actual->tt_member, FALSE);
|
ret = check_type(expected->tt_member, actual->tt_member,
|
||||||
|
FALSE, 0);
|
||||||
if (ret == OK && expected->tt_argcount != -1
|
if (ret == OK && expected->tt_argcount != -1
|
||||||
&& (actual->tt_argcount < expected->tt_min_argcount
|
&& (actual->tt_argcount < expected->tt_min_argcount
|
||||||
|| actual->tt_argcount > expected->tt_argcount))
|
|| actual->tt_argcount > expected->tt_argcount))
|
||||||
@@ -383,7 +386,7 @@ check_type(type_T *expected, type_T *actual, int give_msg)
|
|||||||
for (i = 0; i < expected->tt_argcount; ++i)
|
for (i = 0; i < expected->tt_argcount; ++i)
|
||||||
// Allow for using "any" argument type, lambda's have them.
|
// Allow for using "any" argument type, lambda's have them.
|
||||||
if (actual->tt_args[i] != &t_any && check_type(
|
if (actual->tt_args[i] != &t_any && check_type(
|
||||||
expected->tt_args[i], actual->tt_args[i], FALSE)
|
expected->tt_args[i], actual->tt_args[i], FALSE, 0)
|
||||||
== FAIL)
|
== FAIL)
|
||||||
{
|
{
|
||||||
ret = FAIL;
|
ret = FAIL;
|
||||||
@@ -392,7 +395,7 @@ check_type(type_T *expected, type_T *actual, int give_msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == FAIL && give_msg)
|
if (ret == FAIL && give_msg)
|
||||||
type_mismatch(expected, actual);
|
arg_type_mismatch(expected, actual, argidx);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user