From: Foxe Chen Date: Wed, 31 Dec 2025 09:30:51 +0000 (+0000) Subject: patch 9.1.2032: Vim9: error when using class member in Lambda X-Git-Tag: v9.1.2032^0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83fc7c4d8e07f3a9a5dfb6fb82889e4cfd134e26;p=thirdparty%2Fvim.git patch 9.1.2032: Vim9: error when using class member in Lambda Problem: Vim9: error when using class member in Lambda Solution: Compare against uf_defclass variable (Foxe Chen) closes: #19041 Signed-off-by: Foxe Chen Signed-off-by: Yegappan Lakshmanan Signed-off-by: Christian Brabandt --- diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 7f0326e4a9..5db6c65d12 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -11832,4 +11832,41 @@ func Test_class_selfref_gc() call v9.CheckSourceSuccess(lines) endfunc +" Test if class members can be accessed via a lambda inside a object/class +" method. +func Test_class_member_lambda() + let lines =<< trim END + vim9script + class A + static var regular: string + static var _protected: string + + static def RegularMethod(): string + return A.regular + enddef + + static def _ProtectedMethod(): string + return A._protected + enddef + + def new() + var FuncA: func = () => { + A.regular = "regular" + assert_equal("regular", A.RegularMethod()) + } + var FuncB: func = () => { + A._protected = "protected" + assert_equal("protected", A._ProtectedMethod()) + } + + FuncA() + FuncB() + enddef + endclass + + A.new() + END + call v9.CheckSourceSuccess(lines) +endfunc + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index e2a7f32f44..29b57ab6e3 100644 --- a/src/version.c +++ b/src/version.c @@ -734,6 +734,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 2032, /**/ 2031, /**/ diff --git a/src/vim9compile.c b/src/vim9compile.c index 8a4812ebfb..1b3c7360ae 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -2075,7 +2075,7 @@ compile_lhs_set_oc_member_type( // only inside the class where it is defined. if ((m->ocm_access != VIM_ACCESS_ALL) && ((is_object && !inside_class(cctx, cl)) - || (!is_object && cctx->ctx_ufunc->uf_class != cl))) + || (!is_object && cctx->ctx_ufunc->uf_defclass != cl))) { char *msg = (m->ocm_access == VIM_ACCESS_PRIVATE) ? e_cannot_access_protected_variable_str diff --git a/src/vim9expr.c b/src/vim9expr.c index 5d8b16dc89..a3714e592b 100644 --- a/src/vim9expr.c +++ b/src/vim9expr.c @@ -508,7 +508,7 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type) ((type->tt_type == VAR_OBJECT && !inside_class_hierarchy(cctx, cl)) || (type->tt_type == VAR_CLASS - && cctx->ctx_ufunc->uf_class != cl))) + && cctx->ctx_ufunc->uf_defclass != cl))) { semsg(_(e_cannot_access_protected_method_str), name); goto done;