mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
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:
committed by
Christian Brabandt
parent
56bafd7a6a
commit
c5d2744c04
@@ -5272,7 +5272,7 @@ exec_instructions(ectx_T *ectx)
|
||||
// Useful when used in unpack assignment. Reset at
|
||||
// ISN_DROP.
|
||||
ectx->ec_where.wt_index = gi->gi_index + 1;
|
||||
ectx->ec_where.wt_variable = TRUE;
|
||||
ectx->ec_where.wt_kind = WT_VARIABLE;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -5442,20 +5442,20 @@ exec_instructions(ectx_T *ectx)
|
||||
case ISN_CHECKTYPE:
|
||||
{
|
||||
checktype_T *ct = &iptr->isn_arg.type;
|
||||
int save_wt_variable = ectx->ec_where.wt_variable;
|
||||
int r;
|
||||
where_T where = WHERE_INIT;
|
||||
|
||||
tv = STACK_TV_BOT((int)ct->ct_off);
|
||||
SOURCING_LNUM = iptr->isn_lnum;
|
||||
if (!ectx->ec_where.wt_variable)
|
||||
ectx->ec_where.wt_index = ct->ct_arg_idx;
|
||||
ectx->ec_where.wt_variable = ct->ct_is_var;
|
||||
r = check_typval_type(ct->ct_type, tv, ectx->ec_where);
|
||||
ectx->ec_where.wt_variable = save_wt_variable;
|
||||
if (ct->ct_arg_idx > 0)
|
||||
{
|
||||
where.wt_index = ct->ct_arg_idx;
|
||||
where.wt_kind = ct->ct_is_var ? WT_VARIABLE : WT_ARGUMENT;
|
||||
where.wt_func_name = ectx->ec_where.wt_func_name;
|
||||
}
|
||||
r = check_typval_type(ct->ct_type, tv, where);
|
||||
if (r == FAIL)
|
||||
goto on_error;
|
||||
if (!ectx->ec_where.wt_variable)
|
||||
ectx->ec_where.wt_index = 0;
|
||||
|
||||
// number 0 is FALSE, number 1 is TRUE
|
||||
if (tv->v_type == VAR_NUMBER
|
||||
@@ -5736,8 +5736,7 @@ exec_instructions(ectx_T *ectx)
|
||||
case ISN_DROP:
|
||||
--ectx->ec_stack.ga_len;
|
||||
clear_tv(STACK_TV_BOT(0));
|
||||
ectx->ec_where.wt_index = 0;
|
||||
ectx->ec_where.wt_variable = FALSE;
|
||||
ectx->ec_where = (where_T)WHERE_INIT;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
@@ -6170,8 +6169,7 @@ call_def_function(
|
||||
emsg_silent_def = emsg_silent;
|
||||
did_emsg_def = 0;
|
||||
|
||||
ectx.ec_where.wt_index = 0;
|
||||
ectx.ec_where.wt_variable = FALSE;
|
||||
ectx.ec_where = (where_T)WHERE_INIT;
|
||||
|
||||
/*
|
||||
* Execute the instructions until done.
|
||||
|
Reference in New Issue
Block a user