diff src/vim9expr.c @ 33109:2b5cc29b0a0e v9.0.1838

patch 9.0.1838: Vim9: Cannot modify class member vars from def function Commit: https://github.com/vim/vim/commit/3775f777a6add2a8d5060b40414e9c53062c8cd9 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Fri Sep 1 22:05:45 2023 +0200 patch 9.0.1838: Vim9: Cannot modify class member vars from def function Problem: Vim9: Cannot modify class member vars from def function Solution: Add support for modifying class member variables from a def function closes: #12995 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 01 Sep 2023 22:15:04 +0200
parents 8362975375a4
children 9efd99a717c1
line wrap: on
line diff
--- a/src/vim9expr.c
+++ b/src/vim9expr.c
@@ -438,7 +438,14 @@ compile_class_object_index(cctx_T *cctx,
 	{
 	    ocmember_T *m = &cl->class_class_members[idx];
 	    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;
+		}
 		break;
+	    }
 	}
 	if (idx < cl->class_class_member_count)
 	{