patch 9.0.1829: Vim9 missing access-checks for private vars
Problem: Vim9 missing access-checks for private vars
Solution: Use the proper check for private/readonly variable. Access
level for a member cannot be changed in a class implementing an
interface. Update the code indentation
closes: #12978
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Co-authored-by: Ernie Rael <errael@raelity.com>
diff --git a/src/vim9class.c b/src/vim9class.c
index 4c0c13f..79780c0 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -30,14 +30,14 @@
*/
static int
parse_member(
- exarg_T *eap,
- char_u *line,
- char_u *varname,
- int has_public, // TRUE if "public" seen before "varname"
- char_u **varname_end,
- garray_T *type_list,
- type_T **type_ret,
- char_u **init_expr)
+ exarg_T *eap,
+ char_u *line,
+ char_u *varname,
+ int has_public, // TRUE if "public" seen before "varname"
+ char_u **varname_end,
+ garray_T *type_list,
+ type_T **type_ret,
+ char_u **init_expr)
{
*varname_end = to_name_end(varname, FALSE);
if (*varname == '_' && has_public)
@@ -119,12 +119,12 @@
*/
static int
add_member(
- garray_T *gap,
- char_u *varname,
- char_u *varname_end,
- int has_public,
- type_T *type,
- char_u *init_expr)
+ garray_T *gap,
+ char_u *varname,
+ char_u *varname_end,
+ int has_public,
+ type_T *type,
+ char_u *init_expr)
{
if (ga_grow(gap, 1) == FAIL)
return FAIL;
@@ -357,6 +357,13 @@
where) == FAIL)
return FALSE;
+ if (if_ms[if_i].ocm_access != m->ocm_access)
+ {
+ semsg(_(e_member_str_of_interface_str_has_different_access),
+ if_ms[if_i].ocm_name, intf_class_name);
+ return FALSE;
+ }
+
break;
}
if (cl_i == cl_count)
@@ -622,11 +629,11 @@
*/
static int
update_member_method_lookup_table(
- class_T *ifcl,
- class_T *cl,
- garray_T *objmethods,
- int pobj_method_offset,
- int is_interface)
+ class_T *ifcl,
+ class_T *cl,
+ garray_T *objmethods,
+ int pobj_method_offset,
+ int is_interface)
{
if (ifcl == NULL)
return OK;
@@ -1550,10 +1557,11 @@
*/
type_T *
class_member_type(
- class_T *cl,
- char_u *name,
- char_u *name_end,
- int *member_idx)
+ class_T *cl,
+ char_u *name,
+ char_u *name_end,
+ int *member_idx,
+ omacc_T *access)
{
*member_idx = -1; // not found (yet)
size_t len = name_end - name;
@@ -1564,6 +1572,7 @@
if (STRNCMP(m->ocm_name, name, len) == 0 && m->ocm_name[len] == NUL)
{
*member_idx = i;
+ *access = m->ocm_access;
return m->ocm_type;
}
}