patch 9.1.2032: Vim9: error when using class member in Lambda
Commit:
https://github.com/vim/vim/commit/83fc7c4d8e07f3a9a5dfb6fb82889e4cfd134e26
Author: Foxe Chen <[email protected]>
Date: Wed Dec 31 09:30:51 2025 +0000
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 <[email protected]>
Signed-off-by: Yegappan Lakshmanan <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim
index 7f0326e4a..5db6c65d1 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 e2a7f32f4..29b57ab6e 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 8a4812ebf..1b3c7360a 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 5d8b16dc8..a3714e592 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;
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1vaslM-006vH4-LJ%40256bit.org.