mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.1974: vim9: using contra-variant type-checks
Problem: vim9: using contra-variant type-checks (after v9.0.1959) Solution: Use invariant type checking instead closes: #13248 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
committed by
Christian Brabandt
parent
6d11347260
commit
b32064fedb
@@ -2561,7 +2561,7 @@ inside_class(cctx_T *cctx_arg, class_T *cl)
|
||||
{
|
||||
for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer)
|
||||
if (cctx->ctx_ufunc != NULL
|
||||
&& class_instance_of(cctx->ctx_ufunc->uf_class, cl, TRUE))
|
||||
&& class_instance_of(cctx->ctx_ufunc->uf_class, cl))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
@@ -2871,39 +2871,29 @@ member_not_found_msg(class_T *cl, vartype_T v_type, char_u *name, size_t len)
|
||||
* interfaces matches the class "other_cl".
|
||||
*/
|
||||
int
|
||||
class_instance_of(class_T *cl, class_T *other_cl, int covariance_check)
|
||||
class_instance_of(class_T *cl, class_T *other_cl)
|
||||
{
|
||||
if (cl == other_cl)
|
||||
return TRUE;
|
||||
|
||||
if (covariance_check)
|
||||
// Recursively check the base classes.
|
||||
for (; cl != NULL; cl = cl->class_extends)
|
||||
{
|
||||
// Recursively check the base classes.
|
||||
for (; cl != NULL; cl = cl->class_extends)
|
||||
if (cl == other_cl)
|
||||
return TRUE;
|
||||
// Check the implemented interfaces and the super interfaces
|
||||
for (int i = cl->class_interface_count - 1; i >= 0; --i)
|
||||
{
|
||||
if (cl == other_cl)
|
||||
return TRUE;
|
||||
// Check the implemented interfaces and the super interfaces
|
||||
for (int i = cl->class_interface_count - 1; i >= 0; --i)
|
||||
class_T *intf = cl->class_interfaces_cl[i];
|
||||
while (intf != NULL)
|
||||
{
|
||||
class_T *intf = cl->class_interfaces_cl[i];
|
||||
while (intf != NULL)
|
||||
{
|
||||
if (intf == other_cl)
|
||||
return TRUE;
|
||||
// check the super interfaces
|
||||
intf = intf->class_extends;
|
||||
}
|
||||
if (intf == other_cl)
|
||||
return TRUE;
|
||||
// check the super interfaces
|
||||
intf = intf->class_extends;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// contra-variance
|
||||
for (; other_cl != NULL; other_cl = other_cl->class_extends)
|
||||
if (cl == other_cl)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
@@ -2938,7 +2928,7 @@ f_instanceof(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
|
||||
if (class_instance_of(object_tv->vval.v_object->obj_class,
|
||||
li->li_tv.vval.v_class, TRUE) == TRUE)
|
||||
li->li_tv.vval.v_class) == TRUE)
|
||||
{
|
||||
rettv->vval.v_number = VVAL_TRUE;
|
||||
return;
|
||||
@@ -2947,9 +2937,8 @@ f_instanceof(typval_T *argvars, typval_T *rettv)
|
||||
}
|
||||
else if (classinfo_tv->v_type == VAR_CLASS)
|
||||
{
|
||||
rettv->vval.v_number = class_instance_of(
|
||||
object_tv->vval.v_object->obj_class,
|
||||
classinfo_tv->vval.v_class, TRUE);
|
||||
rettv->vval.v_number = class_instance_of(object_tv->vval.v_object->obj_class,
|
||||
classinfo_tv->vval.v_class);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user