Mercurial > vim
comparison src/testdir/vim9.vim @ 33260:aba1fa2b7d1e v9.0.1898
patch 9.0.1898: Vim9: restrict access to static vars
Commit: https://github.com/vim/vim/commit/c30a90d9b2c029f794cea502f6b824f71e4876dd
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Fri Sep 15 20:14:55 2023 +0200
patch 9.0.1898: Vim9: restrict access to static vars
Problem: Vim9: restrict access to static vars and methods
Solution: Class members are accesible only from the class where they are
defined.
Based on the #13004 discussion, the following changes are made:
1) Static variables and methods are accessible only using the class
name and inside the class where they are defined.
2) Static variables and methods can be used without the class name in
the class where they are defined.
3) Static variables of a super class are not copied to the sub class.
4) A sub class can declare a class variable with the same name as the
super class.
5) When a method or member is found during compilation, use more
specific error messages.
This aligns the Vim9 class variable/method implementation with the Dart
implementation.
Also while at it, ignore duplicate class and object methods.
The access level of an object method can however be changed in a
subclass.
For the tests, use the new CheckSourceFailure() function instead of the
CheckScriptFailure() function in the tests.
closes: #13086
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 15 Sep 2023 20:30:05 +0200 |
parents | dbec60b8c253 |
children | 3f9d9ee5cb7c |
comparison
equal
deleted
inserted
replaced
33259:cf3186a6807f | 33260:aba1fa2b7d1e |
---|---|
105 try | 105 try |
106 exe 'so ' .. fname | 106 exe 'so ' .. fname |
107 finally | 107 finally |
108 chdir(cwd) | 108 chdir(cwd) |
109 delete(fname) | 109 delete(fname) |
110 endtry | |
111 enddef | |
112 | |
113 # :source a list of "lines" and check whether it fails with "error" | |
114 export def CheckSourceFailure(lines: list<string>, error: string, lnum = -3) | |
115 new | |
116 setline(1, lines) | |
117 try | |
118 assert_fails('source', error, lines, lnum) | |
119 finally | |
120 bw! | |
121 endtry | |
122 enddef | |
123 | |
124 # :source a list of "lines" and check whether it fails with the list of | |
125 # "errors" | |
126 export def CheckSourceFailureList(lines: list<string>, errors: list<string>, lnum = -3) | |
127 new | |
128 setline(1, lines) | |
129 try | |
130 assert_fails('source', errors, lines, lnum) | |
131 finally | |
132 bw! | |
133 endtry | |
134 enddef | |
135 | |
136 # :source a list of "lines" and check whether it succeeds | |
137 export def CheckSourceSuccess(lines: list<string>) | |
138 new | |
139 setline(1, lines) | |
140 try | |
141 :source | |
142 finally | |
143 bw! | |
110 endtry | 144 endtry |
111 enddef | 145 enddef |
112 | 146 |
113 export def CheckDefAndScriptSuccess(lines: list<string>) | 147 export def CheckDefAndScriptSuccess(lines: list<string>) |
114 CheckDefSuccess(lines) | 148 CheckDefSuccess(lines) |