patch 9.0.1880: Vim9: Need more tests for inheritance
Problem: Vim9: Need more tests for inheritance
Solution: Add access tests and fixes.
`inside_class` fix from yegappan. `object_index_from_itf_index` fix
access of member on class extending class implementing interface.
Based on tests from Vim9: Class/Object member variable access control #12979
closes: #13032
related: #12979
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
diff --git a/src/vim9class.c b/src/vim9class.c
index cc4410d..a65173d 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -237,10 +237,16 @@
if (cl == itf)
return idx;
- itf2class_T *i2c;
- for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next)
- if (i2c->i2c_class == cl && i2c->i2c_is_method == is_method)
- break;
+ itf2class_T *i2c = NULL;
+ int searching = TRUE;
+ for (class_T *super = cl; super != NULL && searching;
+ super = super->class_extends)
+ for (i2c = itf->class_itf2class; i2c != NULL; i2c = i2c->i2c_next)
+ if (i2c->i2c_class == super && i2c->i2c_is_method == is_method)
+ {
+ searching = FALSE;
+ break;
+ }
if (i2c == NULL)
{
siemsg("class %s not found on interface %s",
@@ -1978,7 +1984,8 @@
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 && cctx->ctx_ufunc->uf_class == cl)
+ if (cctx->ctx_ufunc != NULL
+ && class_instance_of(cctx->ctx_ufunc->uf_class, cl))
return TRUE;
return FALSE;
}