patch 9.1.2012: Vim9: cannot initialize class member with protected var

Problem:  Vim9: cannot initialize class member with protected var
Solution: Allow this to work if this happens within the same class
          (Foxe Chen)

closes: #18949

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Foxe Chen
2025-12-23 20:17:30 +00:00
committed by Christian Brabandt
parent 5e577c7aa8
commit cbcc5babba
7 changed files with 35 additions and 2 deletions
+4 -1
View File
@@ -2122,6 +2122,8 @@ early_ret:
cl->class_object_type.tt_type = VAR_OBJECT;
cl->class_object_type.tt_class = cl;
eap->class = cl;
// Add the class to the script-local variables.
// TODO: handle other context, e.g. in a function
// TODO: does uf_hash need to be cleared?
@@ -3243,7 +3245,8 @@ class_object_index(
if (fp != NULL)
{
// Protected methods are not accessible outside the class
if (*name == '_')
if (fp->uf_defclass != evalarg->eval_class
&& *name == '_')
{
semsg(_(e_cannot_access_protected_method_str), fp->uf_name);
goto done;