0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.0.1867: Vim9: access to interface statics possible

Problem:  Vim9: access to interface statics possible
Solution: Prevent direct access to interface statics

closes: #13007

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
This commit is contained in:
Ernie Rael
2023-09-04 22:30:41 +02:00
committed by Christian Brabandt
parent dccc29c228
commit 18143d3111
12 changed files with 332 additions and 25 deletions

View File

@@ -407,8 +407,27 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
*arg = name_end;
if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type);
return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type);
return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
FALSE);
return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, FALSE);
}
}
for (int i = 0; i < cl->class_class_member_count; ++i)
{
ocmember_T *m = &cl->class_class_members[i];
if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
{
if (*name == '_' && !inside_class(cctx, cl))
{
semsg(_(e_cannot_access_private_member_str), m->ocm_name);
return FAIL;
}
*arg = name_end;
if (cl->class_flags & (CLASS_INTERFACE | CLASS_EXTENDED))
return generate_GET_ITF_MEMBER(cctx, cl, i, m->ocm_type,
TRUE);
return generate_GET_OBJ_MEMBER(cctx, i, m->ocm_type, TRUE);
}
}
@@ -439,6 +458,13 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
ocmember_T *m = &cl->class_class_members[idx];
if (STRNCMP(name, m->ocm_name, len) == 0 && m->ocm_name[len] == NUL)
{
// Note: type->tt_type = VAR_CLASS
if ((cl->class_flags & CLASS_INTERFACE) != 0)
{
semsg(_(e_interface_static_direct_access_str),
cl->class_name, m->ocm_name);
return FAIL;
}
if (*name == '_' && !inside_class(cctx, cl))
{
semsg(_(e_cannot_access_private_member_str), m->ocm_name);