evalarg->eval_getline = eap->ea_getline;
evalarg->eval_cookie = eap->cookie;
}
+ evalarg->eval_class = eap->class;
}
/*
void *cookie; // argument for getline()
#ifdef FEAT_EVAL
cstack_T *cstack; // condition stack for ":if" etc.
+ class_T *class; // Name of class being defined. Used by :class
+ // and :enum commands.
#endif
};
EXTERN evalarg_T EVALARG_EVALUATE
# ifdef DO_INIT
= {EVAL_EVALUATE, 0, NULL, NULL, NULL, NULL, GA_EMPTY, GA_EMPTY, NULL,
- {0, 0, (int)sizeof(char_u *), 20, NULL}, 0, NULL}
+ {0, 0, (int)sizeof(char_u *), 20, NULL}, 0, NULL, NULL}
# endif
;
#endif
// pointer to the lines concatenated for a lambda.
char_u *eval_tofree_lambda;
+
+ // pointer to name of class being constructed
+ class_T *eval_class;
} evalarg_T;
// Flag for expression evaluation.
vim9script
class A
static var _instance: A
+ static var handler: func = A._Internal
var str: string
def _new(str: string)
this.str = str
enddef
+ static def _Internal(): string
+ return "test"
+ enddef
static def GetInstance(str: string): A
if _instance == null
_instance = A._new(str)
var b: A = A.GetInstance('bar')
assert_equal('foo', a.str)
assert_equal('foo', b.str)
+ assert_equal('test', A.handler())
+ END
+ v9.CheckSourceSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+ enum Test
+ A,
+ B,
+ C
+
+ static var handler: func = Test._Internal
+
+ static def _Internal(): string
+ return "test"
+ enddef
+ endenum
+ assert_equal('test', Test.handler())
END
v9.CheckSourceSuccess(lines)
enddef
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 2012,
/**/
2011,
/**/
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?
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;