comparison src/vim9compile.c @ 33075:0346ff4c3ee7 v9.0.1824

patch 9.0.1824: Vim9: private members may be modifiable Commit: https://github.com/vim/vim/commit/5bbcfbc4a260bc082829311086c3a1109c40f2d3 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Wed Aug 30 16:38:26 2023 +0200 patch 9.0.1824: Vim9: private members may be modifiable Problem: Vim9: private members may be modifiable Solution: prevent modification for def function closes: #12963 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Wed, 30 Aug 2023 16:45:10 +0200
parents ba1b40b520e8
children 667a17904f64
comparison
equal deleted inserted replaced
33074:5510af40c77b 33075:0346ff4c3ee7
1864 } 1864 }
1865 else if (use_class) 1865 else if (use_class)
1866 { 1866 {
1867 // for an object or class member get the type of the member 1867 // for an object or class member get the type of the member
1868 class_T *cl = lhs->lhs_type->tt_class; 1868 class_T *cl = lhs->lhs_type->tt_class;
1869 // If it is private member variable, then accessing it outside the
1870 // class is not allowed.
1871 if (*(after + 1) == '_' && !inside_class(cctx, cl))
1872 {
1873 char_u *m_name = vim_strnsave(after + 1, lhs->lhs_end - after);
1874 semsg(_(e_cannot_access_private_member_str), m_name);
1875 vim_free(m_name);
1876 return FAIL;
1877 }
1869 lhs->lhs_member_type = class_member_type(cl, after + 1, 1878 lhs->lhs_member_type = class_member_type(cl, after + 1,
1870 lhs->lhs_end, &lhs->lhs_member_idx); 1879 lhs->lhs_end, &lhs->lhs_member_idx);
1871 if (lhs->lhs_member_idx < 0) 1880 if (lhs->lhs_member_idx < 0)
1872 return FAIL; 1881 return FAIL;
1873 } 1882 }