1
0
forked from aniani/vim

patch 9.0.1804: Vim9: no support for private object methods

Problem:  Vim9: no support for private object methods
Solution: Add support for private object/class methods

closes: #12920

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
Yegappan Lakshmanan
2023-08-27 19:18:23 +02:00
committed by Christian Brabandt
parent 03e44a1d70
commit cd7293bf6c
9 changed files with 691 additions and 5 deletions

View File

@@ -251,6 +251,30 @@ compile_member(int is_slice, int *keeping_dict, cctx_T *cctx)
return OK;
}
/*
* Returns TRUE if the current function is inside the class "cl" or one of the
* parent classes.
*/
static int
inside_class_hierarchy(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 != NULL)
{
class_T *clp = cctx->ctx_ufunc->uf_class;
while (clp != NULL)
{
if (clp == cl)
return TRUE;
clp = clp->class_extends;
}
}
}
return FALSE;
}
/*
* Compile ".member" coming after an object or class.
*/
@@ -348,6 +372,12 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
return FAIL;
}
if (ufunc->uf_private && !inside_class_hierarchy(cctx, cl))
{
semsg(_(e_cannot_access_private_method_str), name);
return FAIL;
}
// Compile the arguments and call the class function or object method.
// The object method will know that the object is on the stack, just
// before the arguments.