Mercurial > vim
diff src/vim9class.c @ 33088:667a17904f64 v9.0.1829
patch 9.0.1829: Vim9 missing access-checks for private vars
Commit: https://github.com/vim/vim/commit/eb91e24d5eca99ad902924911e78f292e9ca0971
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Aug 31 18:10:46 2023 +0200
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>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 31 Aug 2023 18:15:10 +0200 |
parents | 8362975375a4 |
children | d994ba4bd9ca |
line wrap: on
line diff
--- 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 @@ parse_member( */ 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 @@ validate_interface_members( 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 @@ is_valid_constructor(ufunc_T *uf, int is */ 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 @@ cleanup: */ 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 @@ class_member_type( if (STRNCMP(m->ocm_name, name, len) == 0 && m->ocm_name[len] == NUL) { *member_idx = i; + *access = m->ocm_access; return m->ocm_type; } }