diff options
author | Yegappan Lakshmanan <yegappan@yahoo.com> | 2023-10-08 19:07:39 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-08 19:07:39 +0200 |
commit | b852305dbf42f1206ecc6ae414fc200235fe2963 (patch) | |
tree | f488c4f44ee33cfb1725e001eff7f8a88073d613 /src/testdir/test_vim9_class.vim | |
parent | 75b277d35ce207ceb5e3645a962cfd59657d1d73 (diff) |
patch 9.0.2002: Vim9: need cleanup of class related interface codev9.0.2002
Problem: Vim9: need cleanup of class related interface code
Solution: Remove the unused class variable and class method related code
for interfaces.
Remove unused class variable and class method related code for
interfaces.
Refactor the code.
Optimize the object/class member double lookup in compile_lhs().
Change unused global functions to static functions.
closes: #13302
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/testdir/test_vim9_class.vim')
-rw-r--r-- | src/testdir/test_vim9_class.vim | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/src/testdir/test_vim9_class.vim b/src/testdir/test_vim9_class.vim index 555c46cc8e..c911206c9f 100644 --- a/src/testdir/test_vim9_class.vim +++ b/src/testdir/test_vim9_class.vim @@ -975,6 +975,28 @@ def Test_class_new_with_object_member() Check() END v9.CheckSourceSuccess(lines) + + # Try using "this." argument in a class method + lines =<< trim END + vim9script + class A + this.val = 10 + static def Foo(this.val: number) + enddef + endclass + END + v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4) + + # Try using "this." argument in an object method + lines =<< trim END + vim9script + class A + this.val = 10 + def Foo(this.val: number) + enddef + endclass + END + v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4) enddef def Test_class_object_member_inits() @@ -1722,7 +1744,7 @@ def Test_class_member() var a = A.new() var v = a.bar END - v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "A": bar', 5) + v9.CheckSourceFailure(lines, 'E1337: Class variable "bar" not found in class "A"', 5) enddef " These messages should show the defining class of the variable (base class), @@ -4255,7 +4277,7 @@ def Test_private_object_method() var a = A.new() a._Foo() END - v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 9) + v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 9) # Try calling a private method using an object (from a def function) lines =<< trim END @@ -4468,7 +4490,7 @@ def Test_private_object_method() var c = C.new() assert_equal(1234, c._Foo()) END - v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 16) + v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 16) # Using "_" prefix in a method name should fail outside of a class lines =<< trim END @@ -4494,7 +4516,7 @@ def Test_private_class_method() endclass A._Foo() END - v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 8) + v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 8) # Try calling a class private method (from a def function) lines =<< trim END @@ -5122,7 +5144,7 @@ def Test_class_variable_access_using_object() var a = A.new() echo a.svar2 END - v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 8) + v9.CheckSourceFailure(lines, 'E1337: Class variable "svar2" not found in class "A"', 8) # Cannot write to a class variable using an object in script context lines =<< trim END @@ -5597,7 +5619,7 @@ def Test_class_variable() var a = A.new() var i = a.val END - v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 7) + v9.CheckSourceFailure(lines, 'E1337: Class variable "val" not found in class "A"', 7) # Modifying a class variable using an object at function level lines =<< trim END @@ -5969,6 +5991,18 @@ def Test_extend_interface() END v9.CheckSourceSuccess(lines) + # extending empty interface + lines =<< trim END + vim9script + interface A + endinterface + interface B extends A + endinterface + class C implements B + endclass + END + v9.CheckSourceSuccess(lines) + lines =<< trim END vim9script interface A @@ -6567,6 +6601,17 @@ def Test_reserved_varname() o.F() END v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3) + + # class variable name + if kword != 'this' + lines =<< trim eval END + vim9script + class C + public static {kword}: list<number> = [1, 2, 3] + endclass + END + v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3) + endif endfor enddef |