0
0
mirror of https://github.com/vim/vim.git synced 2025-10-06 05:44:14 -04:00

patch 9.0.1824: Vim9: private members may be modifiable

Problem:  Vim9: private members may be modifiable
Solution: prevent modification for def function

closes: #12963

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
Yegappan Lakshmanan
2023-08-30 16:38:26 +02:00
committed by Christian Brabandt
parent 9d8ef7cc43
commit 5bbcfbc4a2
3 changed files with 44 additions and 0 deletions

View File

@@ -3653,4 +3653,37 @@ def Test_dup_member_variable()
v9.CheckScriptFailure(lines, 'E1369: Duplicate member: val')
enddef
" Test for accessing a private member outside a class in a def function
def Test_private_member_access_outside_class()
# private object member variable
var lines =<< trim END
vim9script
class A
this._val = 10
def GetVal(): number
return this._val
enddef
endclass
def T()
var a = A.new()
a._val = 20
enddef
T()
END
v9.CheckScriptFailure(lines, 'E1333: Cannot access private member: _val')
# private class member variable
lines =<< trim END
vim9script
class A
static _val: number = 10
endclass
def T()
A._val = 20
enddef
T()
END
v9.CheckScriptFailure(lines, 'E1333: Cannot access private member: _val')
enddef
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker