]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.2032: Vim9: error when using class member in Lambda v9.1.2032
authorFoxe Chen <chen.foxe@gmail.com>
Wed, 31 Dec 2025 09:30:51 +0000 (09:30 +0000)
committerChristian Brabandt <cb@256bit.org>
Wed, 31 Dec 2025 09:30:51 +0000 (09:30 +0000)
Problem:  Vim9: error when using class member in Lambda
Solution: Compare against uf_defclass variable
          (Foxe Chen)

closes: #19041

Signed-off-by: Foxe Chen <chen.foxe@gmail.com>
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/testdir/test_vim9_class.vim
src/version.c
src/vim9compile.c
src/vim9expr.c

index 7f0326e4a9347c7b4e36f298d36b573464b2e8a7..5db6c65d12c56ca41b2de84b6672fead11dde342 100644 (file)
@@ -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
index e2a7f32f44feb551e5305ceb26d41a60de2aa4ad..29b57ab6e3231404aa659810b4ea1332440f5548 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2032,
 /**/
     2031,
 /**/
index 8a4812ebfbee28a0d056a002b2b859a3bec78794..1b3c7360ae0cece9d82ad30229c2092fc7b9fd5c 100644 (file)
@@ -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
index 5d8b16dc896fb097407a22e383d8d27ce3189194..a3714e592b5d35da3902f701b704cd60ea2e51c0 100644 (file)
@@ -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;