Skip to content

Commit 83fc7c4

Browse files
64-bitmanchrisbra
authored andcommitted
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]>
1 parent 10dc693 commit 83fc7c4

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

src/testdir/test_vim9_class.vim

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11832,4 +11832,41 @@ func Test_class_selfref_gc()
1183211832
call v9.CheckSourceSuccess(lines)
1183311833
endfunc
1183411834

11835+
" Test if class members can be accessed via a lambda inside a object/class
11836+
" method.
11837+
func Test_class_member_lambda()
11838+
let lines =<< trim END
11839+
vim9script
11840+
class A
11841+
static var regular: string
11842+
static var _protected: string
11843+
11844+
static def RegularMethod(): string
11845+
return A.regular
11846+
enddef
11847+
11848+
static def _ProtectedMethod(): string
11849+
return A._protected
11850+
enddef
11851+
11852+
def new()
11853+
var FuncA: func = () => {
11854+
A.regular = "regular"
11855+
assert_equal("regular", A.RegularMethod())
11856+
}
11857+
var FuncB: func = () => {
11858+
A._protected = "protected"
11859+
assert_equal("protected", A._ProtectedMethod())
11860+
}
11861+
11862+
FuncA()
11863+
FuncB()
11864+
enddef
11865+
endclass
11866+
11867+
A.new()
11868+
END
11869+
call v9.CheckSourceSuccess(lines)
11870+
endfunc
11871+
1183511872
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ static char *(features[]) =
734734

735735
static int included_patches[] =
736736
{ /* Add new patch number below this line */
737+
/**/
738+
2032,
737739
/**/
738740
2031,
739741
/**/

src/vim9compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,7 @@ compile_lhs_set_oc_member_type(
20752075
// only inside the class where it is defined.
20762076
if ((m->ocm_access != VIM_ACCESS_ALL) &&
20772077
((is_object && !inside_class(cctx, cl))
2078-
|| (!is_object && cctx->ctx_ufunc->uf_class != cl)))
2078+
|| (!is_object && cctx->ctx_ufunc->uf_defclass != cl)))
20792079
{
20802080
char *msg = (m->ocm_access == VIM_ACCESS_PRIVATE)
20812081
? e_cannot_access_protected_variable_str

src/vim9expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ compile_class_object_index(cctx_T *cctx, char_u **arg, type_T *type)
508508
((type->tt_type == VAR_OBJECT
509509
&& !inside_class_hierarchy(cctx, cl))
510510
|| (type->tt_type == VAR_CLASS
511-
&& cctx->ctx_ufunc->uf_class != cl)))
511+
&& cctx->ctx_ufunc->uf_defclass != cl)))
512512
{
513513
semsg(_(e_cannot_access_protected_method_str), name);
514514
goto done;

0 commit comments

Comments
 (0)