1
0
forked from aniani/vim

patch 9.0.1741: No type checking in interfaces

Problem: No type checking in interfaces
Solution: Implement member type check in vim9 interfaces

Most of the code is a small refactoring to allow the use of a where_T
for signaling the type mismatch, the type checking itself is pretty
simple.

Improve where_T error reports

Let the caller explicitly define the kind of location it's referring to
and free the WT_ARGUMENT enum from its catch-all role.

Implement type checking for interface methods

Follows closely the logic used for type-checking the members.

closes: #12844

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
LemonBoy
2023-08-19 13:02:35 +02:00
committed by Christian Brabandt
parent 56bafd7a6a
commit c5d2744c04
12 changed files with 176 additions and 53 deletions

View File

@@ -678,8 +678,12 @@ check_typval_arg_type(
{
where_T where = WHERE_INIT;
where.wt_index = arg_idx;
where.wt_func_name = func_name;
if (arg_idx > 0)
{
where.wt_index = arg_idx;
where.wt_kind = WT_ARGUMENT;
where.wt_func_name = func_name;
}
return check_typval_type(expected, actual_tv, where);
}
@@ -733,7 +737,11 @@ arg_type_mismatch(type_T *expected, type_T *actual, int arg_idx)
{
where_T where = WHERE_INIT;
where.wt_index = arg_idx;
if (arg_idx > 0)
{
where.wt_index = arg_idx;
where.wt_kind = WT_ARGUMENT;
}
type_mismatch_where(expected, actual, where);
}
@@ -744,25 +752,42 @@ type_mismatch_where(type_T *expected, type_T *actual, where_T where)
char *typename1 = type_name(expected, &tofree1);
char *typename2 = type_name(actual, &tofree2);
if (where.wt_index > 0)
switch (where.wt_kind)
{
if (where.wt_func_name == NULL)
semsg(_(where.wt_variable
? e_variable_nr_type_mismatch_expected_str_but_got_str
: e_argument_nr_type_mismatch_expected_str_but_got_str),
where.wt_index, typename1, typename2);
else
semsg(_(where.wt_variable
? e_variable_nr_type_mismatch_expected_str_but_got_str_in_str
: e_argument_nr_type_mismatch_expected_str_but_got_str_in_str),
where.wt_index, typename1, typename2, where.wt_func_name);
case WT_MEMBER:
semsg(_(e_member_str_type_mismatch_expected_str_but_got_str),
where.wt_func_name, typename1, typename2);
break;
case WT_METHOD:
semsg(_(e_method_str_type_mismatch_expected_str_but_got_str),
where.wt_func_name, typename1, typename2);
break;
case WT_VARIABLE:
if (where.wt_func_name == NULL)
semsg(_(e_variable_nr_type_mismatch_expected_str_but_got_str),
where.wt_index, typename1, typename2);
else
semsg(_(e_variable_nr_type_mismatch_expected_str_but_got_str_in_str),
where.wt_index, typename1, typename2, where.wt_func_name);
break;
case WT_ARGUMENT:
if (where.wt_func_name == NULL)
semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str),
where.wt_index, typename1, typename2);
else
semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str_in_str),
where.wt_index, typename1, typename2, where.wt_func_name);
break;
case WT_UNKNOWN:
if (where.wt_func_name == NULL)
semsg(_(e_type_mismatch_expected_str_but_got_str),
typename1, typename2);
else
semsg(_(e_type_mismatch_expected_str_but_got_str_in_str),
typename1, typename2, where.wt_func_name);
break;
}
else if (where.wt_func_name == NULL)
semsg(_(e_type_mismatch_expected_str_but_got_str),
typename1, typename2);
else
semsg(_(e_type_mismatch_expected_str_but_got_str_in_str),
typename1, typename2, where.wt_func_name);
vim_free(tofree1);
vim_free(tofree2);
}