From 62a6923470827acbf124df41134ae6df52f334e6 Mon Sep 17 00:00:00 2001 From: Bram Moolenaar Date: Tue, 24 Jan 2023 15:07:04 +0000 Subject: patch 9.0.1240: cannot access a private object member in a lambda Problem: Cannot access a private object member in a lambda defined inside the class. Solution: Go up the context stack to find the class. (closes #11866) --- src/vim9class.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/vim9class.c') diff --git a/src/vim9class.c b/src/vim9class.c index 0262e025d..484500576 100644 --- a/src/vim9class.c +++ b/src/vim9class.c @@ -1387,6 +1387,19 @@ class_member_index(char_u *name, size_t len, class_T **cl_ret, cctx_T *cctx) return -1; } +/* + * Return TRUE if current context "cctx_arg" is inside class "cl". + * Return FALSE if not. + */ + int +inside_class(cctx_T *cctx_arg, class_T *cl) +{ + for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer) + if (cctx->ctx_ufunc != NULL && cctx->ctx_ufunc->uf_class == cl) + return TRUE; + return FALSE; +} + /* * Make a copy of an object. */ -- cgit v1.2.1