diff options
author | LemonBoy <thatlemon@gmail.com> | 2023-08-19 13:02:35 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-08-19 13:04:53 +0200 |
commit | c5d2744c045f9ad058cbc799f2434d90a6d83516 (patch) | |
tree | 76990a51b671ae6ab1973fe1f22d7109befc8b40 /src/vim9type.c | |
parent | 56bafd7a6a79203b86f7165a7bbac5730c170f64 (diff) |
patch 9.0.1741: No type checking in interfacesv9.0.1741
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>
Diffstat (limited to 'src/vim9type.c')
-rw-r--r-- | src/vim9type.c | 65 |
1 files changed, 45 insertions, 20 deletions
diff --git a/src/vim9type.c b/src/vim9type.c index 0dd74ee184..1363a1c3e7 100644 --- a/src/vim9type.c +++ b/src/vim9type.c @@ -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); } |