annotate src/testdir/test_vim9_class.vim @ 35062:f57990be7526 v9.1.0376

patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored Commit: https://github.com/vim/vim/commit/ac7731895c996acef4d02b784f9952749226e203 Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sat Apr 27 11:36:12 2024 +0200 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored Problem: Vim9: Trailing commands after class/enum keywords ignored Solution: Remove EX_TRLBAR keyword from command definition (Yegappan Lakshmanan) closes: #14649 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Sat, 27 Apr 2024 12:00:03 +0200
parents 8c9e43278b2c
children 60a7fae99560
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1 " Test Vim9 classes
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3 source check.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
4 import './vim9.vim' as v9
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
5
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
6 def Test_class_basic()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7 # Class supported only in "vim9script"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
8 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
9 class NotWorking
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
10 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
11 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
12 v9.CheckSourceFailure(lines, 'E1316: Class can only be defined in Vim9 script', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
13
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
14 # First character in a class name should be capitalized.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
15 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
16 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
17 class notWorking
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
18 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
19 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
20 v9.CheckSourceFailure(lines, 'E1314: Class name must start with an uppercase letter: notWorking', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
21
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
22 # Only alphanumeric characters are supported in a class name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
23 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
24 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
25 class Not@working
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
26 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
27 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
28 v9.CheckSourceFailure(lines, 'E1315: White space required after name: Not@working', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
29
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
30 # Unsupported keyword (instead of class)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
31 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
32 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
33 abstract noclass Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
34 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
35 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
36 v9.CheckSourceFailure(lines, 'E475: Invalid argument: noclass Something', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
37
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
38 # Only the complete word "class" should be recognized
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
39 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
40 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
41 abstract classy Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
42 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
43 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
44 v9.CheckSourceFailure(lines, 'E475: Invalid argument: classy Something', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
45
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
46 # The complete "endclass" should be specified.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
47 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
48 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
49 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
50 endcl
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
51 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
52 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: endcl', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
53
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
54 # Additional words after "endclass"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
55 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
56 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
57 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
58 endclass school's out
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
59 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
60 v9.CheckSourceFailure(lines, "E488: Trailing characters: school's out", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
61
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
62 # Additional commands after "endclass"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
63 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
64 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
65 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
66 endclass | echo 'done'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
67 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
68 v9.CheckSourceFailure(lines, "E488: Trailing characters: | echo 'done'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
69
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
70 # Additional command after "class name"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
71 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
72 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
73 class Something | var x = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
74 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
75 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
76 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
77
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
78 # Additional command after "object variable"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
79 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
80 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
81 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
82 var l: list<number> = [] | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
83 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
84 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
85 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
86
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
87 # Additional command after "class variable"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
88 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
89 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
90 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
91 static var d = {a: 10} | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
92 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
93 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
94 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
95
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
96 # Additional command after "object method"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
97 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
98 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
99 class Something
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
100 def Foo() | var y = 10
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
101 enddef
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
102 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
103 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
104 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var y = 10", 3)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
105
34508
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
106 # Try to define a class with the same name as an existing variable
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
107 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
108 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
109 var Something: list<number> = [1]
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
110 class Thing
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
111 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
112 interface Api
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
113 endinterface
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
114 class Something extends Thing implements Api
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
115 var v1: string = ''
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
116 def Foo()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
117 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
118 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
119 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
120 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "Something"', 7)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
121
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
122 # Use old "this." prefixed member variable declaration syntax (without initialization)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
123 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
124 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
125 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
126 this.count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
127 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
128 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
129 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
130
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
131 # Use old "this." prefixed member variable declaration syntax (with initialization)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
132 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
133 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
134 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
135 this.count: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
136 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
137 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
138 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
139
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
140 # Use old "this." prefixed member variable declaration syntax (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
141 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
142 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
143 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
144 this.count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
145 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
146 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
147 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.count = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
148
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
149 # Use "this" without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
150 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
151 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
152 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
153 this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
154 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
155 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
156 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
157
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
158 # Use "this." without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
159 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
160 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
161 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
162 this.
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
163 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
164 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
165 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this.', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
166
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
167 # Space between "this" and ".<variable>"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
168 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
169 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
170 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
171 this .count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
172 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
173 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
174 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this .count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
175
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
176 # Space between "this." and the member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
177 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
178 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
179 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
180 this. count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
181 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
182 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
183 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: this. count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
184
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
185 # Use "that" instead of "this"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
186 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
187 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
188 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
189 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
190 that.count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
191 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
192 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
193 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: that.count', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
194
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
195 # Use "variable" instead of "var" for member variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
196 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
197 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
198 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
199 variable count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
200 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
201 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
202 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
203
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
204 # Use "variable" instead of "var" for member variable declaration (with initialization)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
205 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
206 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
207 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
208 variable count: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
209 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
210 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
211 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
212
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
213 # Use "variable" instead of "var" for member variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
214 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
215 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
216 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
217 variable count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
218 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
219 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
220 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: variable count = 42', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
221
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
222 # Use a non-existing member variable in new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
223 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
224 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
225 class Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
226 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
227 this.state = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
228 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
229 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
230 var obj = Something.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
231 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
232 v9.CheckSourceFailure(lines, 'E1326: Variable "state" not found in object "Something"', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
233
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
234 # Space before ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
235 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
236 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
237 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
238 var count : number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
239 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
240 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
241 v9.CheckSourceFailure(lines, 'E1059: No white space allowed before colon: count : number', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
242
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
243 # No space after ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
244 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
245 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
246 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
247 var count:number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
248 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
249 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
250 v9.CheckSourceFailure(lines, "E1069: White space required after ':'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
251
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
252 # Missing ":var" in a "var" member variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
253 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
254 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
255 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
256 var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
257 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
258 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
259 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var: number', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
260
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
261 # Missing ":var" in a "var" member variable declaration (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
262 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
263 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
264 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
265 var: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
266 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
267 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
268 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var: number = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
269
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
270 # Missing ":var" in a "var" member variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
271 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
272 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
273 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
274 var = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
275 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
276 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
277 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: var = 42', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
278
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
279 # Test for unsupported comment specifier
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
280 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
281 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
282 class Something
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
283 # comment
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
284 #{
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
285 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
286 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
287 v9.CheckSourceFailure(lines, 'E1170: Cannot use #{ to start a comment', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
288
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
289 # Test for using class as a bool
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
290 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
291 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
292 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
293 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
294 if A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
295 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
296 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
297 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
298
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
299 # Test for using object as a bool
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
300 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
301 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
302 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
303 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
304 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
305 if a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
306 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
307 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
308 v9.CheckSourceFailure(lines, 'E1320: Using an Object as a Number', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
309
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
310 # Test for using class as a float
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
311 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
312 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
313 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
314 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
315 sort([1.1, A], 'f')
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
316 END
33933
aceaf677dd92 patch 9.0.2163: Vim9: type can be assigned to list/dict
Christian Brabandt <cb@256bit.org>
parents: 33929
diff changeset
317 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
318
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
319 # Test for using object as a float
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
320 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
321 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
322 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
323 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
324 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
325 sort([1.1, a], 'f')
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
326 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
327 v9.CheckSourceFailure(lines, 'E1322: Using an Object as a Float', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
328
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
329 # Test for using class as a string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
330 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
331 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
332 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
333 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
334 :exe 'call ' .. A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
335 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
336 v9.CheckSourceFailure(lines, 'E1405: Class "A" cannot be used as a value', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
337
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
338 # Test for using object as a string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
339 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
340 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
341 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
342 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
343 var a = A.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
344 :exe 'call ' .. a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
345 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
346 v9.CheckSourceFailure(lines, 'E1324: Using an Object as a String', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
347
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
348 # Test creating a class with member variables and methods, calling a object
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
349 # method. Check for using type() and typename() with a class and an object.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
350 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
351 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
352
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
353 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
354 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
355 var col: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
356
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
357 # make a nicely formatted string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
358 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
359 return $'({this.lnum}, {this.col})'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
360 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
361 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
362
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
363 # use the automatically generated new() method
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
364 var pos = TextPosition.new(2, 12)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
365 assert_equal(2, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
366 assert_equal(12, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
367
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
368 # call an object method
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
369 assert_equal('(2, 12)', pos.ToString())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
370
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
371 assert_equal(v:t_class, type(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
372 assert_equal(v:t_object, type(pos))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
373 assert_equal('class<TextPosition>', typename(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
374 assert_equal('object<TextPosition>', typename(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
375 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
376 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
377
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
378 # When referencing object methods, space cannot be used after a "."
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
379 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
380 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
381 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
382 def Foo(): number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
383 return 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
384 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
385 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
386 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
387 var v = a. Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
388 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
389 v9.CheckSourceFailure(lines, "E1202: No white space allowed after '.'", 8)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
390
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
391 # Using an object without specifying a method or a member variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
392 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
393 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
394 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
395 def Foo(): number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
396 return 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
397 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
398 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
399 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
400 var v = a.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
401 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
402 v9.CheckSourceFailure(lines, 'E15: Invalid expression: "a."', 8)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
403
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
404 # Error when parsing the arguments of an object method.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
405 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
406 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
407 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
408 def Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
409 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
410 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
411 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
412 var v = a.Foo(,)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
413 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
414 v9.CheckSourceFailure(lines, 'E15: Invalid expression: "a.Foo(,)"', 7)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
415
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
416 # Use a multi-line initialization for a member variable
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
417 lines =<< trim END
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
418 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
419 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
420 var y = {
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
421 X: 1
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
422 }
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
423 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
424 var a = A.new()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
425 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
426 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
427 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
428
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
429 " Tests for object/class methods in a class
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
430 def Test_class_def_method()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
431 # Using the "public" keyword when defining an object method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
432 var lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
433 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
434 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
435 public def Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
436 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
437 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
438 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
439 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
440
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
441 # Using the "public" keyword when defining a class method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
442 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
443 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
444 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
445 public static def Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
446 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
447 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
448 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
449 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
450
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
451 # Using the "public" keyword when defining an object protected method
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
452 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
453 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
454 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
455 public def _Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
456 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
457 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
458 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
459 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
460
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
461 # Using the "public" keyword when defining a class protected method
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
462 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
463 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
464 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
465 public static def _Foo()
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
466 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
467 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
468 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
469 v9.CheckSourceFailure(lines, 'E1388: public keyword not supported for a method', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
470
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
471 # Using a "def" keyword without an object method name
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
472 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
473 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
474 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
475 def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
476 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
477 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
478 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
479 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: def', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
480
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
481 # Using a "def" keyword without a class method name
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
482 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
483 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
484 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
485 static def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
486 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
487 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
488 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
489 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: static def', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
490 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
491
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
492 def Test_class_defined_twice()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
493 # class defined twice should fail
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
494 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
495 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
496 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
497 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
498 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
499 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
500 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
501 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "There"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
502
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
503 # one class, reload same script twice is OK
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
504 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
505 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
506 class There
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
507 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
508 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
509 writefile(lines, 'XclassTwice.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
510 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
511 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
512 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
513
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
514 def Test_returning_null_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
515 # this was causing an internal error
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
516 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
517 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
518
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
519 class BufferList
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
520 def Current(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
521 return null_object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
522 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
523 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
524
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
525 var buffers = BufferList.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
526 echo buffers.Current()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
527 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
528 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
529 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
530
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
531 def Test_using_null_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
532 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
533 @_ = null_class.member
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
534 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
535 v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
536 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
537
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
538 def Test_class_interface_wrong_end()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
539 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
540 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
541 abstract class SomeName
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
542 var member = 'text'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
543 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
544 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
545 v9.CheckSourceFailure(lines, 'E476: Invalid command: endinterface, expected endclass', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
546
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
547 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
548 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
549 export interface AnotherName
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
550 var member: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
551 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
552 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
553 v9.CheckSourceFailure(lines, 'E476: Invalid command: endclass, expected endinterface', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
554 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
555
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
556 def Test_object_not_set()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
557 # Use an uninitialized object in script context
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
558 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
559 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
560
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
561 class State
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
562 var value = 'xyz'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
563 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
564
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
565 var state: State
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
566 var db = {'xyz': 789}
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
567 echo db[state.value]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
568 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
569 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
570
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
571 # Use an uninitialized object from a def function
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
572 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
573 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
574
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
575 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
576 var id: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
577 def Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
578 echo 'Method1' .. this.id
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
579 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
580 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
581
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
582 var obj: Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
583 def Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
584 obj.Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
585 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
586 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
587 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
588 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
589
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
590 # Pass an uninitialized object variable to a "new" function and try to call an
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
591 # object method.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
592 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
593 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
594
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
595 class Background
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
596 var background = 'dark'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
597 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
598
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
599 class Colorscheme
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
600 var _bg: Background
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
601
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
602 def GetBackground(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
603 return this._bg.background
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
604 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
605 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
606
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
607 var bg: Background # UNINITIALIZED
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
608 echo Colorscheme.new(bg).GetBackground()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
609 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
610 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
611
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
612 # TODO: this should not give an error but be handled at runtime
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
613 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
614 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
615
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
616 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
617 var id: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
618 def Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
619 echo 'Method1' .. this.id
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
620 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
621 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
622
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
623 var obj = null_object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
624 def Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
625 obj.Method1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
626 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
627 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
628 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
629 v9.CheckSourceFailure(lines, 'E1363: Incomplete type', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
630 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
631
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
632 " Null object assignment and comparison
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
633 def Test_null_object_assign_compare()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
634 var lines =<< trim END
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
635 vim9script
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
636
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
637 var nullo = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
638 def F(): any
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
639 return nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
640 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
641 assert_equal('object<Unknown>', typename(F()))
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
642
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
643 var o0 = F()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
644 assert_true(o0 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
645 assert_true(o0 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
646
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
647 var o1: any = nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
648 assert_true(o1 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
649 assert_true(o1 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
650
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
651 def G()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
652 var x = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
653 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
654
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
655 class C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
656 endclass
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
657 var o2: C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
658 assert_true(o2 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
659 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
660
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
661 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
662 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
663
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
664 o2 = C.new()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
665 assert_true(o2 != null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
666
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
667 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
668 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
669 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
670 v9.CheckSourceSuccess(lines)
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
671 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
672
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
673 " Test for object member initialization and disassembly
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
674 def Test_class_member_initializer()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
675 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
676 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
677
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
678 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
679 var lnum: number = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
680 var col: number = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
681
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
682 # constructor with only the line number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
683 def new(lnum: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
684 this.lnum = lnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
685 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
686 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
687
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
688 var pos = TextPosition.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
689 assert_equal(3, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
690 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
691
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
692 var instr = execute('disassemble TextPosition.new')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
693 assert_match('new\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
694 '0 NEW TextPosition size \d\+\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
695 '\d PUSHNR 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
696 '\d STORE_THIS 0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
697 '\d PUSHNR 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
698 '\d STORE_THIS 1\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
699 'this.lnum = lnum\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
700 '\d LOAD arg\[-1]\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
701 '\d PUSHNR 0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
702 '\d LOAD $0\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
703 '\d\+ STOREINDEX object\_s*' ..
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
704 '\d\+ RETURN object.*',
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
705 instr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
706 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
707 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
708 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
709
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
710 def Test_member_any_used_as_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
711 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
712 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
713
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
714 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
715 var value: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
716 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
717
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
718 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
719 var inner: any
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
720 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
721
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
722 def F(outer: Outer)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
723 outer.inner.value = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
724 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
725
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
726 var inner_obj = Inner.new(0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
727 var outer_obj = Outer.new(inner_obj)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
728 F(outer_obj)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
729 assert_equal(1, inner_obj.value)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
730 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
731 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
732
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
733 # Try modifying a protected variable using an "any" object
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
734 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
735 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
736
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
737 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
738 var _value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
739 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
740
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
741 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
742 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
743 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
744
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
745 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
746 outer.inner._value = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
747 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
748
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
749 var inner_obj = Inner.new('a')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
750 var outer_obj = Outer.new(inner_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
751 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
752 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
753 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_value" in class "Inner"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
754
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
755 # Try modifying a non-existing variable using an "any" object
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
756 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
757 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
758
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
759 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
760 var value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
761 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
762
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
763 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
764 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
765 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
766
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
767 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
768 outer.inner.someval = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
769 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
770
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
771 var inner_obj = Inner.new('a')
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
772 var outer_obj = Outer.new(inner_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
773 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
774 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
775 v9.CheckSourceFailure(lines, 'E1326: Variable "someval" not found in object "Inner"', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
776 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
777
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
778 " Nested assignment to a object variable which is of another class type
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
779 def Test_assignment_nested_type()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
780 var lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
781 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
782
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
783 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
784 public var value: number = 0
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
785 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
786
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
787 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
788 var inner: Inner
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
789 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
790
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
791 def F(outer: Outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
792 outer.inner.value = 1
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
793 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
794
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
795 def Test_assign_to_nested_typed_member()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
796 var inner = Inner.new(0)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
797 var outer = Outer.new(inner)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
798 F(outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
799 assert_equal(1, inner.value)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
800 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
801
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
802 Test_assign_to_nested_typed_member()
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
803
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
804 var script_inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
805 var script_outer = Outer.new(script_inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
806 script_outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
807 assert_equal(1, script_inner.value)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
808 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
809 v9.CheckSourceSuccess(lines)
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
810
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
811 # Assignment where target item is read only in :def
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
812 lines =<< trim END
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
813 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
814
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
815 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
816 var value: number = 0
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
817 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
818
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
819 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
820 var inner: Inner
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
821 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
822
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
823 def F(outer: Outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
824 outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
825 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
826
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
827 def Test_assign_to_nested_typed_member()
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
828 var inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
829 var outer = Outer.new(inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
830 F(outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
831 assert_equal(1, inner.value)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
832 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
833
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
834 Test_assign_to_nested_typed_member()
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
835 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
836 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "Inner" is not writable', 1)
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
837
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
838 # Assignment where target item is read only script level
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
839 lines =<< trim END
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
840 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
841
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
842 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
843 var value: number = 0
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
844 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
845
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
846 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
847 var inner: Inner
33309
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
848 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
849
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
850 def F(outer: Outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
851 outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
852 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
853
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
854 var script_inner = Inner.new(0)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
855 var script_outer = Outer.new(script_inner)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
856 script_outer.inner.value = 1
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
857 assert_equal(1, script_inner.value)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
858 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
859 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "Inner" is not writable', 17)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
860 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
861
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
862 def Test_assignment_with_operator()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
863 # Use "+=" to assign to a object variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
864 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
865 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
866
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
867 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
868 public var x: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
869
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
870 def Add(n: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
871 this.x += n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
872 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
873 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
874
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
875 var f = Foo.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
876 f.Add(17)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
877 assert_equal(20, f.x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
878
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
879 def AddToFoo(obj: Foo)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
880 obj.x += 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
881 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
882
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
883 AddToFoo(f)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
884 assert_equal(23, f.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
885 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
886 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
887 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
888
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
889 def Test_list_of_objects()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
890 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
891 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
892
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
893 class Foo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
894 def Add()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
895 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
896 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
897
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
898 def ProcessList(fooList: list<Foo>)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
899 for foo in fooList
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
900 foo.Add()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
901 endfor
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
902 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
903
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
904 var l: list<Foo> = [Foo.new()]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
905 ProcessList(l)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
906 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
907 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
908 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
909
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
910 def Test_expr_after_using_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
911 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
912 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
913
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
914 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
915 var label: string = ''
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
916 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
917
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
918 def Foo(): Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
919 var v = Something.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
920 echo 'in Foo(): ' .. typename(v)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
921 return v
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
922 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
923
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
924 Foo()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
925 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
926 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
927 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
928
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
929 def Test_class_default_new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
930 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
931 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
932
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
933 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
934 var lnum: number = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
935 var col: number = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
936 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
937
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
938 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
939 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
940 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
941
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
942 pos = TextPosition.new(v:none, v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
943 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
944 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
945
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
946 pos = TextPosition.new(3, 22)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
947 assert_equal(3, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
948 assert_equal(22, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
949
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
950 pos = TextPosition.new(v:none, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
951 assert_equal(1, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
952 assert_equal(33, pos.col)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
953 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
954 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
955
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
956 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
957 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
958 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
959 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
960 var age: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
961 var education: string = "unknown"
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
962
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
963 def new(this.name, this.age = v:none, this.education = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
964 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
965 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
967 var piet = Person.new("Piet")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
968 assert_equal("Piet", piet.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
969 assert_equal(42, piet.age)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
970 assert_equal("unknown", piet.education)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
971
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
972 var chris = Person.new("Chris", 4, "none")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
973 assert_equal("Chris", chris.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
974 assert_equal(4, chris.age)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
975 assert_equal("none", chris.education)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
976 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
977 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
978
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
979 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
980 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
981 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
982 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
983 var age: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
984 var education: string = "unknown"
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
985
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
986 def new(this.name, this.age = v:none, this.education = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
987 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
988 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
989
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
990 var missing = Person.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
991 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
992 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: new', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
993
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
994 # Using a specific value to initialize an instance variable in the new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
995 # method.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
996 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
997 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
998 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
999 var val: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1000 def new(this.val = 'a')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1001 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1002 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1003 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1004 v9.CheckSourceFailure(lines, "E1328: Constructor default value must be v:none: = 'a'", 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1005 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1006
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1007 def Test_class_new_with_object_member()
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1008 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1009 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1010
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1011 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1012 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1013 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1014 def new(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1015 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1016 def newVals(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1017 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1018 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1019
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1020 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1021 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1022 var c = C.new('cats', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1023 assert_equal('cats', c.str)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1024 assert_equal(2, c.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1025
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1026 c = C.newVals('dogs', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1027 assert_equal('dogs', c.str)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1028 assert_equal(4, c.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1029 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1030 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1031 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1032 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1033
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1034 Check()
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1035 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1036 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1037
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1038 lines =<< trim END
33379
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1039 vim9script
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1040
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1041 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1042 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1043 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1044 def new(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1045 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1046 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1047
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1048 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1049 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1050 var c = C.new(1, 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1051 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1052 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1053 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1054 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1055
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1056 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1057 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1058 v9.CheckSourceFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got number', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1059
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1060 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1061 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1062
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1063 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1064 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1065 var num: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1066 def newVals(this.str, this.num)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1067 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1068 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1069
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1070 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1071 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1072 var c = C.newVals('dogs', 'apes')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1073 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1074 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1075 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1076 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1077
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1078 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1079 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1080 v9.CheckSourceFailure(lines, 'E1013: Argument 2: type mismatch, expected number but got string', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1081
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1082 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1083 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1084
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1085 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1086 var str: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1087 def new(str: any)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1088 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1089 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1090
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1091 def Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1092 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1093 var c = C.new(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1094 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1095 assert_report($'Unexpected exception was caught: {v:exception}')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1096 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1097 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1098
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1099 Check()
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1100 END
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1101 v9.CheckSourceSuccess(lines)
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1102
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1103 # Try using "this." argument in a class method
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1104 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1105 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1106 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1107 var val = 10
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1108 static def Foo(this.val: number)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1109 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1110 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1111 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1112 v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1113
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1114 # Try using "this." argument in an object method
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1115 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1116 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1117 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1118 var val = 10
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1119 def Foo(this.val: number)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1120 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1121 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1122 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1123 v9.CheckSourceFailure(lines, 'E1390: Cannot use an object variable "this.val" except with the "new" method', 4)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1124 enddef
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1125
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1126 def Test_class_object_member_inits()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1127 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1128 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1129 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1130 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1131 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1132 var addcol: number = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1133 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1134
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1135 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1136 assert_equal(0, pos.lnum)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1137 assert_equal(1, pos.col)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1138 assert_equal(2, pos.addcol)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1139 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1140 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1141
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1142 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1143 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1144 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1145 var lnum
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1146 var col = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1147 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1148 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1149 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1150
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1151 # If the type is not specified for a member, then it should be set during
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1152 # object creation and not when defining the class.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1153 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1154 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1155
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1156 var init_count = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1157 def Init(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1158 init_count += 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1159 return 'foo'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1160 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1161
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1162 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1163 var str1 = Init()
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1164 var str2: string = Init()
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1165 var col = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1166 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1167
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1168 assert_equal(init_count, 0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1169 var a = A.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1170 assert_equal(init_count, 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1171 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1172 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1173
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1174 # Test for initializing an object member with an unknown variable/type
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1175 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1176 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1177 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1178 var value = init_val
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1179 endclass
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1180 var a = A.new()
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1181 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1182 v9.CheckSourceFailure(lines, 'E1001: Variable not found: init_val', 1)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1183
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1184 # Test for initializing an object member with an special type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1185 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1186 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1187 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1188 var value: void
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1189 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1190 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1191 v9.CheckSourceFailure(lines, 'E1330: Invalid type for object variable: void', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1192 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1193
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1194 " Test for instance variable access
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1195 def Test_instance_variable_access()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1196 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1197 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1198 class Triple
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1199 var _one = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1200 var two = 2
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1201 public var three = 3
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1202
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1203 def GetOne(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1204 return this._one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1205 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1206 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1207
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1208 var trip = Triple.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1209 assert_equal(1, trip.GetOne())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1210 assert_equal(2, trip.two)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1211 assert_equal(3, trip.three)
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1212 assert_fails('echo trip._one', 'E1333: Cannot access protected variable "_one" in class "Triple"')
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1213
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1214 assert_fails('trip._one = 11', 'E1333: Cannot access protected variable "_one" in class "Triple"')
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1215 assert_fails('trip.two = 22', 'E1335: Variable "two" in class "Triple" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1216 trip.three = 33
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1217 assert_equal(33, trip.three)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1218
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1219 assert_fails('trip.four = 4', 'E1326: Variable "four" not found in object "Triple"')
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1220 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1221 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1222
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1223 # Test for a public member variable name beginning with an underscore
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1224 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1225 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1226 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1227 public var _val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1228 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1229 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
1230 v9.CheckSourceFailure(lines, 'E1332: public variable name cannot start with underscore: public var _val = 10', 3)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1231
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1232 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1233 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1234
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1235 class MyCar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1236 var make: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1237 var age = 5
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1238
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1239 def new(make_arg: string)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1240 this.make = make_arg
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1241 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1242
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1243 def GetMake(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1244 return $"make = {this.make}"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1245 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1246 def GetAge(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1247 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1248 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1249 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1250
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1251 var c = MyCar.new("abc")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1252 assert_equal('make = abc', c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1253
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1254 c = MyCar.new("def")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1255 assert_equal('make = def', c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1256
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1257 var c2 = MyCar.new("123")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1258 assert_equal('make = 123', c2.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1259
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1260 def CheckCar()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1261 assert_equal("make = def", c.GetMake())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1262 assert_equal(5, c.GetAge())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1263 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1264 CheckCar()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1265 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1266 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1267
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1268 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1269 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1270
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1271 class MyCar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1272 var make: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1273
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1274 def new(make_arg: string)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1275 this.make = make_arg
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1276 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1277 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1278
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1279 var c = MyCar.new("abc")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1280 var c = MyCar.new("def")
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1281 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1282 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "c"', 12)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1283
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1284 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1285 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1286
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1287 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1288 var x: list<number> = []
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1289
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1290 def Add(n: number): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1291 this.x->add(n)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1292 return this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1293 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1294 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1295
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1296 echo Foo.new().Add(1).Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1297 echo Foo.new().Add(1).Add(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1298 .x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1299 echo Foo.new().Add(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1300 .Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1301 echo Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1302 .Add(1).Add(2).x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1303 echo Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1304 .Add(1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1305 .Add(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1306 .x
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1307 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1308 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1309
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1310 # Test for "public" cannot be abbreviated
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1311 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1312 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1313 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1314 pub var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1315 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1316 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1317 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: pub var val = 1', 3)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1318
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1319 # Test for "public" keyword must be followed by "var" or "static".
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1320 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1321 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1322 class Something
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1323 public val = 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1324 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1325 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
1326 v9.CheckSourceFailure(lines, 'E1331: public must be followed by "var" or "static"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1327
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1328 # Modify a instance variable using the class name in the script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1329 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1330 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1331 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1332 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1333 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1334 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1335 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1336 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 5)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1337
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1338 # Read a instance variable using the class name in the script context
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1339 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1340 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1341 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1342 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1343 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1344 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1345 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1346 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 5)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1347
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1348 # Modify a instance variable using the class name in a def function
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
1349 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
1350 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1351 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1352 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1353 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1354 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1355 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1356 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1357 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1358 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1359 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1360
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1361 # Read a instance variable using the class name in a def function
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1362 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1363 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1364 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1365 public var val = 1
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1366 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1367 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1368 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1369 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1370 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1371 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1372 v9.CheckSourceFailure(lines, 'E1376: Object variable "val" accessible only using class "A" object', 1)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1373
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1374 # Access from child class extending a class:
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1375 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1376 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1377 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1378 var ro_obj_var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1379 public var rw_obj_var = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1380 var _priv_obj_var = 30
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1381 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1382
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1383 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1384 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1385 var x: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1386 x = this.ro_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1387 this.ro_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1388 x = this.rw_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1389 this.rw_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1390 x = this._priv_obj_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1391 this._priv_obj_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1392 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1393 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1394
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1395 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1396 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1397 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1398 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1399 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1400
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1401 " Test for class variable access
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1402 def Test_class_variable_access()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1403 # Test for "static" cannot be abbreviated
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1404 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1405 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1406 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1407 stat var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1408 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1409 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1410 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: stat var val = 1', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1411
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1412 # Test for "static" cannot be followed by "public".
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1413 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1414 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1415 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1416 static public var val = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1417 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1418 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1419 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1420
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1421 # A readonly class variable cannot be modified from a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1422 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1423 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1424 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1425 static var ro_class_var = 40
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1426 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1427
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1428 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1429 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1430 A.ro_class_var = 50
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1431 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1432 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1433
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1434 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1435 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1436 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1437 v9.CheckSourceFailure(lines, 'E1335: Variable "ro_class_var" in class "A" is not writable', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1438
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1439 # A protected class variable cannot be accessed from a child class
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1440 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1441 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1442 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1443 static var _priv_class_var = 60
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1444 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1445
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1446 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1447 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1448 var i = A._priv_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1449 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1450 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1451
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1452 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1453 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1454 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1455 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_priv_class_var" in class "A"', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1456
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1457 # A protected class variable cannot be modified from a child class
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1458 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1459 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1460 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1461 static var _priv_class_var = 60
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1462 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1463
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1464 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1465 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1466 A._priv_class_var = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1467 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1468 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1469
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1470 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1471 b.Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1472 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1473 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_priv_class_var" in class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1474
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1475 # Access from child class extending a class and from script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1476 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1477 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1478 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1479 static var ro_class_var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1480 public static var rw_class_var = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1481 static var _priv_class_var = 30
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1482 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1483
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1484 class B extends A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1485 def Foo()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1486 var x: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1487 x = A.ro_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1488 assert_equal(10, x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1489 x = A.rw_class_var
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1490 assert_equal(25, x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1491 A.rw_class_var = 20
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1492 assert_equal(20, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1493 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1494 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1495
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1496 assert_equal(10, A.ro_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1497 assert_equal(20, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1498 A.rw_class_var = 25
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1499 assert_equal(25, A.rw_class_var)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1500 var b = B.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1501 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1502 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1503 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1504 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1505
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1506 def Test_class_object_compare()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1507 var class_lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1508 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1509 class Item
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1510 var nr = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1511 var name = 'xx'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1512 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1513 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1514
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1515 # used at the script level and in a compiled function
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1516 var test_lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1517 var i1 = Item.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1518 assert_equal(i1, i1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1519 assert_true(i1 is i1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1520 var i2 = Item.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1521 assert_equal(i1, i2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1522 assert_false(i1 is i2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1523 var i3 = Item.new(0, 'xx')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1524 assert_equal(i1, i3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1525
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1526 var io1 = Item.new(1, 'xx')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1527 assert_notequal(i1, io1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1528 var io2 = Item.new(0, 'yy')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1529 assert_notequal(i1, io2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1530 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1531
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1532 v9.CheckSourceSuccess(class_lines + test_lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1533 v9.CheckSourceSuccess(
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1534 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1535
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1536 for op in ['>', '>=', '<', '<=', '=~', '!~']
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1537 var op_lines = [
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1538 'var i1 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1539 'var i2 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1540 'echo i1 ' .. op .. ' i2',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1541 ]
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1542 v9.CheckSourceFailure(class_lines + op_lines, 'E1153: Invalid operation for object', 8)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1543 v9.CheckSourceFailure(class_lines
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1544 + ['def Test()'] + op_lines + ['enddef', 'Test()'], 'E1153: Invalid operation for object')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1545 endfor
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1546 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1547
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1548 def Test_object_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1549 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1550 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1551
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1552 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1553 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1554 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1555 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1556 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1557 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1558 class TwoMore extends Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1559 var more = 9
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1560 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1561
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1562 var o: One = One.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1563 var t: Two = Two.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1564 var m: TwoMore = TwoMore.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1565 var tm: Two = TwoMore.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1566
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1567 t = m
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1568 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1569 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1570
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1571 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1572 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1573
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1574 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1575 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1576 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1577 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1578 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1579 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1580
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1581 var o: One = Two.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1582 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1583 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<One> but got object<Two>', 10)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1584
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1585 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1586 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1587
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1588 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1589 def GetMember(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1590 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1591 class Two implements One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1592 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1593 def GetMember(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1594 return this.one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1595 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1596 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1597
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1598 var o: One = Two.new(5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1599 assert_equal(5, o.GetMember())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1600 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1601 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1602
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1603 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1604 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1605
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1606 class Num
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1607 var n: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1608 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1609
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1610 def Ref(name: string): func(Num): Num
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1611 return (arg: Num): Num => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1612 return eval(name)(arg)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1613 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1614 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1615
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1616 const Fn = Ref('Double')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1617 var Double = (m: Num): Num => Num.new(m.n * 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1618
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1619 echo Fn(Num.new(4))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1620 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1621 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1622 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1623
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1624 def Test_class_member()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1625 # check access rules
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1626 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1627 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1628 class TextPos
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1629 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1630 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1631 static var counter = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1632 static var _secret = 7
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1633 public static var anybody = 42
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1634
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1635 static def AddToCounter(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1636 counter += nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1637 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1638 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1639
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1640 assert_equal(0, TextPos.counter)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1641 TextPos.AddToCounter(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1642 assert_equal(3, TextPos.counter)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1643 assert_fails('echo TextPos.noSuchMember', 'E1337: Class variable "noSuchMember" not found in class "TextPos"')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1644
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1645 def GetCounter(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1646 return TextPos.counter
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1647 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1648 assert_equal(3, GetCounter())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1649
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1650 assert_fails('TextPos.noSuchMember = 2', 'E1337: Class variable "noSuchMember" not found in class "TextPos"')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1651 assert_fails('TextPos.counter = 5', 'E1335: Variable "counter" in class "TextPos" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1652 assert_fails('TextPos.counter += 5', 'E1335: Variable "counter" in class "TextPos" is not writable')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1653
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1654 assert_fails('echo TextPos._secret', 'E1333: Cannot access protected variable "_secret" in class "TextPos"')
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1655 assert_fails('TextPos._secret = 8', 'E1333: Cannot access protected variable "_secret" in class "TextPos"')
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1656
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1657 assert_equal(42, TextPos.anybody)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1658 TextPos.anybody = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1659 assert_equal(12, TextPos.anybody)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1660 TextPos.anybody += 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1661 assert_equal(17, TextPos.anybody)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1662 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1663 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1664
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1665 # example in the help
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1666 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1667 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1668 class OtherThing
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1669 var size: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1670 static var totalSize: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1671
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1672 def new(this.size)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1673 totalSize += this.size
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1674 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1675 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1676 assert_equal(0, OtherThing.totalSize)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1677 var to3 = OtherThing.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1678 assert_equal(3, OtherThing.totalSize)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1679 var to7 = OtherThing.new(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1680 assert_equal(10, OtherThing.totalSize)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1681 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1682 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1683
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1684 # using static class member twice
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1685 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1686 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1687
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1688 class HTML
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1689 static var author: string = 'John Doe'
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1690
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1691 static def MacroSubstitute(s: string): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1692 return substitute(s, '{{author}}', author, 'gi')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1693 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1694 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1695
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1696 assert_equal('some text', HTML.MacroSubstitute('some text'))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1697 assert_equal('some text', HTML.MacroSubstitute('some text'))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1698 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1699 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1700
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1701 # access protected member in lambda
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1702 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1703 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1704
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1705 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1706 var _x: number = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1707
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1708 def Add(n: number): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1709 const F = (): number => this._x + n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1710 return F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1711 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1712 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1713
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1714 var foo = Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1715 assert_equal(5, foo.Add(5))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1716 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1717 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1718
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1719 # access protected member in lambda body
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1720 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1721 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1722
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1723 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1724 var _x: number = 6
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1725
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1726 def Add(n: number): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1727 var Lam = () => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1728 this._x = this._x + n
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1729 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1730 Lam()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1731 return this._x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1732 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1733 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1734
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1735 var foo = Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1736 assert_equal(13, foo.Add(7))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1737 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1738 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1739
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1740 # check shadowing
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1741 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1742 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1743
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1744 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1745 static var count = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1746 def Method(count: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1747 echo count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1748 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1749 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1750
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1751 var s = Some.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1752 s.Method(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1753 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1754 v9.CheckSourceFailure(lines, 'E1340: Argument already declared in the class: count', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1755
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
1756 # Use a local variable in a method with the same name as a class variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1757 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1758 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1759
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1760 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1761 static var count = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1762 def Method(arg: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1763 var count = 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1764 echo arg count
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1765 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1766 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1767
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1768 var s = Some.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1769 s.Method(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1770 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1771 v9.CheckSourceFailure(lines, 'E1341: Variable already declared in the class: count', 1)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1772
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1773 # Test for using an invalid type for a member variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1774 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1775 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1776 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1777 var val: xxx
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1778 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1779 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1780 v9.CheckSourceFailure(lines, 'E1010: Type not recognized: xxx', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1781
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1782 # Test for setting a member on a null object
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1783 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1784 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1785 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1786 public var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1787 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1788
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1789 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1790 var obj: A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1791 obj.val = ""
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1792 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1793 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1794 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1795 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1796
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1797 # Test for accessing a member on a null object
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1798 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1799 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1800 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1801 var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1802 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1803
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1804 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1805 var obj: A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1806 echo obj.val
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1807 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1808 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1809 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1810 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1811
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1812 # Test for setting a member on a null object, at script level
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1813 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1814 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1815 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1816 public var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1817 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1818
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1819 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1820 obj.val = ""
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1821 END
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
1822 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 7)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1823
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1824 # Test for accessing a member on a null object, at script level
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1825 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1826 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1827 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1828 var val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1829 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1830
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1831 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1832 echo obj.val
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1833 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1834 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 7)
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1835
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1836 # Test for no space before or after the '=' when initializing a member
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1837 # variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1838 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1839 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1840 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1841 var val: number= 10
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1842 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1843 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1844 v9.CheckSourceFailure(lines, "E1004: White space required before and after '='", 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1845 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1846 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1847 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1848 var val: number =10
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1849 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1850 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1851 v9.CheckSourceFailure(lines, "E1004: White space required before and after '='", 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1852
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1853 # Access a non-existing member
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1854 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1855 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1856 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1857 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1858 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1859 var v = a.bar
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1860 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1861 v9.CheckSourceFailure(lines, 'E1326: Variable "bar" not found in object "A"', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1862 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1863
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1864 " These messages should show the defining class of the variable (base class),
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1865 " not the class that did the reference (super class)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1866 def Test_defining_class_message()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1867 var lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1868 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1869
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1870 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1871 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1872 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1873
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1874 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1875 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1876
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1877 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1878 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1879 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1880 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 11)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1881 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1882 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1883
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1884 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1885 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1886 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1887
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1888 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1889 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1890
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1891 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1892 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1893 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1894 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1895 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1896 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1897 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 2)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1898 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1899 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1900
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1901 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1902 var v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1903 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1904
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1905 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1906 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1907
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1908 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1909 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1910 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1911 v9.CheckSourceFailure(lines, 'E1335: Variable "v1" in class "Base" is not writable', 11)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1912 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1913 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1914
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1915 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1916 var v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1917 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1918
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1919 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1920 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1921
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1922 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1923 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1924 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1925 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1926 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1927 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1928
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1929 # Attempt to read a protected variable that is in the middle
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1930 # of the class hierarchy.
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1931 v9.CheckSourceFailure(lines, 'E1335: Variable "v1" in class "Base" is not writable', 2)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1932 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1933 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1934
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1935 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1936 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1937
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1938 class Base extends Base0
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1939 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1940 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1941
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1942 class Child extends Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1943 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1944
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1945 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1946 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1947 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1948 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1949 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1950 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1951 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Base"', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1952
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1953 # Attempt to read a protected variable that is at the start
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1954 # of the class hierarchy.
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1955 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1956 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1957
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1958 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1959 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1960
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1961 class Base extends Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1962 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1963
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1964 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1965 var _v1: list<list<number>>
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1966 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1967
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1968 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1969 var o = Child.new()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1970 var x = o._v1
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1971 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1972 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1973 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1974 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "Child"', 2)
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1975 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1976
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1977 func Test_class_garbagecollect()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1978 let lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1979 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1980
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1981 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1982 var p = [2, 3]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1983 static var pl = ['a', 'b']
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1984 static var pd = {a: 'a', b: 'b'}
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1985 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1986
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1987 echo Point.pl Point.pd
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1988 call test_garbagecollect_now()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1989 echo Point.pl Point.pd
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1990 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1991 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1992
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1993 let lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1994 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1995
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1996 interface View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1997 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1998
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1999 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2000 var view: View
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2001 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2002
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2003 class MyView implements View
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2004 var widget: Widget
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2005
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2006 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2007 # this will result in a circular reference to this object
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2008 var widget = Widget.new(this)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2009 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2010 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2011
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2012 var view = MyView.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2013
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2014 # overwrite "view", will be garbage-collected next
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2015 view = MyView.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2016 test_garbagecollect_now()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2017 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2018 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2019 endfunc
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2020
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2021 " Test interface garbage collection
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2022 func Test_interface_garbagecollect()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2023 let lines =<< trim END
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2024 vim9script
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2025
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2026 interface I
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2027 var ro_obj_var: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
2028
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2029 def ObjFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2030 endinterface
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2031
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2032 class A implements I
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2033 static var ro_class_var: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2034 public static var rw_class_var: number = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2035 static var _priv_class_var: number = 30
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2036 var ro_obj_var: number = 40
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2037 var _priv_obj_var: number = 60
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2038
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2039 static def _ClassBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2040 return _priv_class_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2041 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2042
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2043 static def ClassFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2044 return ro_class_var + rw_class_var + A._ClassBar()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2045 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2046
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2047 def _ObjBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2048 return this._priv_obj_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2049 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2050
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2051 def ObjFoo(): number
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2052 return this.ro_obj_var + this._ObjBar()
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2053 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2054 endclass
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2055
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2056 assert_equal(60, A.ClassFoo())
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2057 var o = A.new()
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2058 assert_equal(100, o.ObjFoo())
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2059 test_garbagecollect_now()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2060 assert_equal(60, A.ClassFoo())
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2061 assert_equal(100, o.ObjFoo())
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2062 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2063 call v9.CheckSourceSuccess(lines)
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2064 endfunc
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2065
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2066 def Test_class_method()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2067 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2068 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2069 class Value
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2070 var value = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2071 static var objects = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2072
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2073 def new(v: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2074 this.value = v
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2075 ++objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2076 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2077
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2078 static def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2079 return objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2080 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2081 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2082
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2083 assert_equal(0, Value.GetCount())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2084 var v1 = Value.new(2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2085 assert_equal(1, Value.GetCount())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2086 var v2 = Value.new(7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2087 assert_equal(2, Value.GetCount())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2088 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2089 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2090
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2091 # Test for cleaning up after a class definition failure when using class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2092 # functions.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2093 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2094 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2095 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2096 static def Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2097 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2098 aaa
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2099 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2100 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2101 v9.CheckSourceFailure(lines, 'E1318: Not a valid command in a class: aaa', 5)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2102
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2103 # Test for calling a class method from another class method without the class
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2104 # name prefix.
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2105 lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2106 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2107 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2108 static var myList: list<number> = [1]
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2109 static def Foo(n: number)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2110 myList->add(n)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2111 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2112 static def Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2113 Foo(2)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2114 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2115 def Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2116 Foo(3)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2117 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2118 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2119 A.Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2120 var a = A.new()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2121 a.Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2122 assert_equal([1, 2, 3], A.myList)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2123 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2124 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2125 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2126
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2127 def Test_class_defcompile()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2128 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2129 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2130
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2131 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2132 def Fo(i: number): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2133 return i
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2134 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2135 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2136
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2137 defcompile C.Fo
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2138 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2139 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected string but got number', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2140
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2141 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2142 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2143
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2144 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2145 static def Fc(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2146 return 'x'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2147 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2148 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2149
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2150 defcompile C.Fc
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2151 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2152 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2153
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2154 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2155 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2156
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2157 class C
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2158 static def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2159 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2160 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2161
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2162 defcompile C.new
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2163 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2164 v9.CheckSourceFailure(lines, 'E1370: Cannot define a "new" method as static', 5)
33068
d42927c6e556 patch 9.0.1821: Vim9 constructors are always static
Christian Brabandt <cb@256bit.org>
parents: 33047
diff changeset
2165
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2166 # Trying to compile a function using a non-existing class variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2167 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2168 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2169 defcompile x.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2170 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2171 v9.CheckSourceFailure(lines, 'E475: Invalid argument: x.Foo()', 2)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2172
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2173 # Trying to compile a function using a variable which is not a class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2174 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2175 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2176 var x: number
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2177 defcompile x.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2178 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2179 v9.CheckSourceFailure(lines, 'E475: Invalid argument: x.Foo()', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2180
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2181 # Trying to compile a function without specifying the name
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2182 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2183 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2184 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2185 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2186 defcompile A.
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2187 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2188 v9.CheckSourceFailure(lines, 'E475: Invalid argument: A.', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2189
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2190 # Trying to compile a non-existing class object member function
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2191 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2192 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2193 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2194 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2195 var a = A.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2196 defcompile a.Foo()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2197 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
2198 v9.CheckSourceFailureList(lines, ['E1326: Variable "Foo" not found in object "A"', 'E475: Invalid argument: a.Foo()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2199 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2200
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2201 def Test_class_object_to_string()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2202 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2203 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2204 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2205 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2206 var col = 22
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2207 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2208
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2209 assert_equal("class TextPosition", string(TextPosition))
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2210
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2211 var pos = TextPosition.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2212 assert_equal("object of TextPosition {lnum: 1, col: 22}", string(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2213 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2214 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2215 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2216
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2217 def Test_interface_basics()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2218 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2219 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2220 interface Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2221 var ro_var: list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2222 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2223 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2224 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2225 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2226
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2227 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2228 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2229 static var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2230 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2231 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2232 v9.CheckSourceFailure(lines, 'E1342: Interface can only be defined in Vim9 script', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2233
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2234 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2235 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2236
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2237 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2238 var value: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2239 def Method(value: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2240 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2241 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2242 # The argument name and the object member name are the same, but this is not a
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2243 # problem because object members are always accessed with the "this." prefix.
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2244 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2245
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2246 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2247 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2248 interface somethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2249 static var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2250 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2251 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2252 v9.CheckSourceFailure(lines, 'E1343: Interface name must start with an uppercase letter: somethingWrong', 2)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2253
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2254 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2255 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2256 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2257 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2258 var count = 7
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2259 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2260 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2261 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2262 v9.CheckSourceFailure(lines, 'E1344: Cannot initialize a variable in an interface', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2263
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2264 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2265 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2266 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2267 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2268 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2269 def GetCount(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2270 return 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2271 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2272 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2273 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2274 v9.CheckSourceFailure(lines, 'E1345: Not a valid command in an interface: return 5', 6)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2275
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2276 # Additional commands after "interface name"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2277 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2278 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2279 interface Something | var x = 10 | var y = 20
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2280 endinterface
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2281 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2282 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = 10", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
2283
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2284 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2285 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2286 export interface EnterExit
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2287 def Enter(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2288 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2289 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2290 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2291 writefile(lines, 'XdefIntf.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2292
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2293 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2294 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2295 import './XdefIntf.vim' as defIntf
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2296 export def With(ee: defIntf.EnterExit, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2297 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2298 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2299 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2300 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2301 ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2302 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2303 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2304 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2305 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2306
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2307 var imported =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2308 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2309 export abstract class EnterExit
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2310 def Enter(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2311 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2312 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2313 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2314 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2315 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2316 writefile(imported, 'XdefIntf2.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2317
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2318 lines[1] = " import './XdefIntf2.vim' as defIntf"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2319 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2320 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2321
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2322 " Test for using string() with an interface
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2323 def Test_interface_to_string()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2324 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2325 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2326 interface Intf
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2327 def Method(nr: number)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2328 endinterface
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2329 assert_equal("interface Intf", string(Intf))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2330 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2331 v9.CheckSourceSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2332 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2333
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2334 def Test_class_implements_interface()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2335 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2336 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2337
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2338 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2339 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2340 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2341 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2342
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2343 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2344 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2345 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2346 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2347 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2348 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2349
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2350 interface Another
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2351 var member: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2352 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2353
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2354 class AnotherImpl implements Some, Another
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2355 var member = 'abc'
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2356 var count = 20
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2357 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2358 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2359 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2360 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2361 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2362 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2363
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2364 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2365 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2366
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2367 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2368 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2369 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2370
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2371 class SomeImpl implements Some implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2372 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2373 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2374 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2375 v9.CheckSourceFailure(lines, 'E1350: Duplicate "implements"', 7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2376
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2377 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2378 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2379
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2380 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2381 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2382 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2383
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2384 class SomeImpl implements Some, Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2385 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2386 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2387 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2388 v9.CheckSourceFailure(lines, 'E1351: Duplicate interface after "implements": Some', 7)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2389
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2390 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2391 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2392
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2393 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2394 var counter: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2395 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2396 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2397
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2398 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2399 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2400 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2401 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2402 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2403 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2404 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2405 v9.CheckSourceFailure(lines, 'E1348: Variable "counter" of interface "Some" is not implemented', 13)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2406
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2407 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2408 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2409
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2410 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2411 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2412 def Methods(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2413 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2414
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2415 class SomeImpl implements Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2416 var count: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2417 def Method(nr: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2418 echo nr
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2419 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2420 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2421 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2422 v9.CheckSourceFailure(lines, 'E1349: Method "Methods" of interface "Some" is not implemented', 13)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2423
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2424 # Check different order of members in class and interface works.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2425 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2426 vim9script
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2427
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2428 interface Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2429 var label: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2430 var errpos: number
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2431 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2432
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2433 # order of members is opposite of interface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2434 class Failure implements Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2435 public var lnum: number = 5
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2436 var errpos: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2437 var label: string = 'label'
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2438 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2439
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2440 def Test()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2441 var result: Result = Failure.new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2442
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2443 assert_equal('label', result.label)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2444 assert_equal(42, result.errpos)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2445 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2446
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2447 Test()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2448 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2449 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2450
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2451 # Interface name after "extends" doesn't end in a space or NUL character
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2452 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2453 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2454 interface A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2455 endinterface
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2456 class B extends A"
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2457 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2458 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2459 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A"', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2460
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2461 # Trailing characters after a class name
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2462 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2463 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2464 class A bbb
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2465 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2466 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2467 v9.CheckSourceFailure(lines, 'E488: Trailing characters: bbb', 2)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2468
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2469 # using "implements" with a non-existing class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2470 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2471 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2472 class A implements B
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2473 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2474 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2475 v9.CheckSourceFailure(lines, 'E1346: Interface name not found: B', 3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2476
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2477 # using "implements" with a regular class
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2478 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2479 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2480 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2481 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2482 class B implements A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2483 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2484 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2485 v9.CheckSourceFailure(lines, 'E1347: Not a valid interface: A', 5)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2486
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2487 # using "implements" with a variable
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2488 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2489 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2490 var T: number = 10
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2491 class A implements T
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2492 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2493 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2494 v9.CheckSourceFailure(lines, 'E1347: Not a valid interface: T', 4)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2495
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2496 # implements should be followed by a white space
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2497 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2498 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2499 interface A
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2500 endinterface
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2501 class B implements A;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2502 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2503 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2504 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A;', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2505
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2506 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2507 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2508
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2509 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2510 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2511 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2512 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2513 def IsEven(nr: number): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2514 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2515 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2516 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2517 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(number): string', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2518
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2519 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2520 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2521
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2522 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2523 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2524 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2525 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2526 def IsEven(nr: bool): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2527 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2528 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2529 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2530 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(bool): bool', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2531
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2532 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2533 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2534
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2535 interface One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2536 def IsEven(nr: number): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2537 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2538 class Two implements One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2539 def IsEven(nr: number, ...extra: list<number>): bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2540 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2541 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2542 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2543 v9.CheckSourceFailure(lines, 'E1383: Method "IsEven": type mismatch, expected func(number): bool but got func(number, ...list<number>): bool', 9)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2544
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2545 # access superclass interface members from subclass, mix variable order
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2546 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2547 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2548
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2549 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2550 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2551 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2552 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2553
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2554 # NOTE: the order is swapped
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2555 class A implements I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2556 var mvar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2557 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2558 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2559 public static var svar1: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2560 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2561 svar1 = 11
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2562 svar2 = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2563 this.mvar1 = 111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2564 this.mvar2 = 112
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2565 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2566 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2567
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2568 class B extends A
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2569 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2570 this.mvar1 = 121
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2571 this.mvar2 = 122
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2572 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2573 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2574
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2575 class C extends B
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2576 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2577 this.mvar1 = 131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2578 this.mvar2 = 132
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2579 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2580 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2581
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2582 def F2(i: I1): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2583 return [ i.mvar1, i.mvar2 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2584 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2585
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2586 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2587 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2588 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2589
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2590 assert_equal([111, 112], F2(oa))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2591 assert_equal([121, 122], F2(ob))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2592 assert_equal([131, 132], F2(oc))
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2593 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2594 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2595
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2596 # Access superclass interface members from subclass, mix variable order.
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2597 # Two interfaces, one on A, one on B; each has both kinds of variables
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2598 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2599 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2600
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2601 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2602 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2603 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2604 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2605
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2606 interface I2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2607 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2608 var mvar4: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2609 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2610
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2611 class A implements I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2612 public static var svar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2613 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2614 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2615 var mvar2: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2616 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2617 svar1 = 11
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2618 svar2 = 12
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2619 this.mvar1 = 111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2620 this.mvar2 = 112
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2621 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2622 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2623
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2624 class B extends A implements I2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2625 static var svar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2626 static var svar4: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2627 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2628 var mvar4: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2629 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2630 svar3 = 23
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2631 svar4 = 24
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2632 this.mvar1 = 121
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2633 this.mvar2 = 122
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2634 this.mvar3 = 123
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2635 this.mvar4 = 124
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2636 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2637 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2638
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2639 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2640 public static var svar5: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2641 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2642 svar5 = 1001
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2643 this.mvar1 = 131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2644 this.mvar2 = 132
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2645 this.mvar3 = 133
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2646 this.mvar4 = 134
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2647 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2648 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2649
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2650 def F2(i: I1): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2651 return [ i.mvar1, i.mvar2 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2652 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2653
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2654 def F4(i: I2): list<number>
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2655 return [ i.mvar3, i.mvar4 ]
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2656 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2657
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2658 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2659 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2660 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2661
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2662 assert_equal([[111, 112]], [F2(oa)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2663 assert_equal([[121, 122], [123, 124]], [F2(ob), F4(ob)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2664 assert_equal([[131, 132], [133, 134]], [F2(oc), F4(oc)])
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2665 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2666 v9.CheckSourceSuccess(lines)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2667
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2668 # Using two interface names without a space after the ","
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2669 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2670 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2671 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2672 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2673 interface B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2674 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2675 class C implements A,B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2676 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2677 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2678 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A,B', 6)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2679
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2680 # No interface name after a comma
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2681 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2682 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2683 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2684 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2685 class B implements A,
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2686 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2687 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2688 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 4)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2689
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2690 # No interface name after implements
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2691 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2692 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2693 class A implements
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2694 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2695 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2696 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2697 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2698
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2699 def Test_call_interface_method()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2700 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2701 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2702 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2703 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2704 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2705
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2706 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2707 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2708 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2709 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2710 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2711
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2712 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2713 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2714 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2715
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2716 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2717 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2718 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2719 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2720 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2721 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2722
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2723 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2724 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2725 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2726 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2727 g:result ..= 'base'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2728 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2729 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2730
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2731 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2732 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2733 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2734 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2735 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2736
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2737 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2738 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2739 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2740
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2741 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2742 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2743 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2744 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2745 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2746 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2747
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2748 # method of interface returns a value
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2749 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2750 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2751 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2752 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2753 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2754
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2755 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2756 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2757 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2758 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2759 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2760 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2761
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2762 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2763 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2764 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2765 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2766
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2767 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2768 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2769 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2770 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2771 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2772 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2773
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2774 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2775 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2776 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2777 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2778 return null_string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2779 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2780 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2781
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2782 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2783 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2784 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2785 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2786 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2787 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2788
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2789 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2790 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2791 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2792 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2793
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2794 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2795 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2796 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2797 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2798 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2799 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2800
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2801 # No class that implements the interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2802 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2803 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2804
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2805 interface IWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2806 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2807 def Exit(): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2808 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2809
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2810 def With1(ee: IWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2811 var r = ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2812 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2813
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2814 defcompile
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2815 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2816 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2817 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2818
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2819 def Test_class_used_as_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2820 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2821 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2822
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2823 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2824 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2825 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2826 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2827
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2828 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2829 p = Point.new(2, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2830 assert_equal(2, p.x)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2831 assert_equal(33, p.y)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2832 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2833 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2834
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2835 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2836 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2837
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2838 interface HasX
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2839 var x: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2840 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2841
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2842 class Point implements HasX
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2843 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2844 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2845 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2846
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2847 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2848 p = Point.new(2, 33)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2849 var hx = p
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2850 assert_equal(2, hx.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2851 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2852 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2853
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2854 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2855 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2856
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2857 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2858 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2859 var y = 0
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2860 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2861
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2862 var p: Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2863 p = 'text'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2864 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2865 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected object<Point> but got string', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2866 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2867
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2868 def Test_class_extends()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2869 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2870 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2871 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2872 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2873 def GetOne(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2874 return this.one
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2875 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2876 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2877 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2878 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2879 def GetTotal(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2880 return this.one + this.two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2881 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2882 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2883 var o = Child.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2884 assert_equal(1, o.one)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2885 assert_equal(2, o.two)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2886 assert_equal(1, o.GetOne())
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2887 assert_equal(3, o.GetTotal())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2888 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2889 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2890
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2891 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2892 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2893 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2894 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2895 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2896 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2897 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2898 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2899 var o = Child.new(3, 44)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2900 assert_equal(3, o.one)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2901 assert_equal(44, o.two)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2902 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2903 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2904
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2905 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2906 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2907 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2908 var one = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2909 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2910 class Child extends Base extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2911 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2912 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2913 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2914 v9.CheckSourceFailure(lines, 'E1352: Duplicate "extends"', 5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2915
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2916 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2917 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2918 class Child extends BaseClass
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2919 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2920 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2921 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2922 v9.CheckSourceFailure(lines, 'E1353: Class name not found: BaseClass', 4)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2923
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2924 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2925 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2926 var SomeVar = 99
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2927 class Child extends SomeVar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2928 var two = 2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2929 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2930 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2931 v9.CheckSourceFailure(lines, 'E1354: Cannot extend SomeVar', 5)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2932
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2933 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2934 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2935 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2936 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2937 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2938 return this.name
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2939 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2940 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2941
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2942 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2943 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2944 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2945 return super.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2946 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2947 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2948
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2949 var o = Child.new('John', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2950 assert_equal('John: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2951 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2952 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2953
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2954 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2955 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2956 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2957 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2958 def ToString(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2959 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2960 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2961 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2962 return this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2963 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2964 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2965 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2966 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: ToString', 9)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2967
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2968 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2969 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2970 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2971 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2972 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2973 return super .ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2974 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2975 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2976 var o = Child.new(42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2977 echo o.ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2978 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2979 v9.CheckSourceFailure(lines, 'E1356: "super" must be followed by a dot', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2980
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2981 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2982 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2983 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2984 var name: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2985 def ToString(): string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2986 return this.name
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2987 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2988 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2989
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2990 var age = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2991 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2992 return super.ToString() .. ': ' .. age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2993 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2994 echo ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2995 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2996 v9.CheckSourceFailure(lines, 'E1357: Using "super" not in a class method', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2997
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2998 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2999 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3000 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3001 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3002 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3003 return super.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3004 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3005 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3006 var o = Child.new(42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3007 echo o.ToString()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3008 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3009 v9.CheckSourceFailure(lines, 'E1358: Using "super" not in a child class', 1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3010
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3011 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3012 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3013 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3014 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3015 static def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3016 return 'Base class'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3017 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3018 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3019
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3020 class Child extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3021 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3022 def ToString(): string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3023 return Base.ToString() .. ': ' .. this.age
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3024 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3025 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3026
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3027 var o = Child.new('John', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3028 assert_equal('Base class: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3029 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3030 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3031
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3032 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3033 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3034 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3035 var value = 1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3036 def new(init: number)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3037 this.value = number + 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3038 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3039 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3040 class Child extends Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3041 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3042 this.new(3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3043 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3044 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3045 var c = Child.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3046 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3047 v9.CheckSourceFailure(lines, 'E1385: Class method "new" accessible only using class "Child"', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3048
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3049 # base class with more than one object member
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3050 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3051 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3052
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3053 class Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3054 var success: bool
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3055 var value: any = null
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3056 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3057
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3058 class Success extends Result
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3059 def new(this.value = v:none)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3060 this.success = true
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3061 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3062 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3063
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3064 var v = Success.new('asdf')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3065 assert_equal("object of Success {success: true, value: 'asdf'}", string(v))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3066 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3067 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3068
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3069 # class name after "extends" doesn't end in a space or NUL character
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3070 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3071 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3072 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3073 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3074 class B extends A"
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3075 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3076 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3077 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3078 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3079
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3080 def Test_using_base_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3081 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3082 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3083
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3084 class BaseEE
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3085 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3086 return null
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3087 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3088 def Exit(resource: any): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3089 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3090 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3091
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3092 class ChildEE extends BaseEE
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3093 def Enter(): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3094 return 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3095 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3096
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3097 def Exit(resource: number): void
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3098 g:result ..= '/exit'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3099 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3100 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3101
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3102 def With(ee: BaseEE)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3103 var r = ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3104 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3105 g:result ..= r
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3106 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3107 g:result ..= '/finally'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3108 ee.Exit(r)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3109 endtry
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3110 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3111
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3112 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3113 With(ChildEE.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3114 assert_equal('42/finally/exit', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3115 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3116 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3117 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3118
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3119 # Using super, Child invokes Base method which has optional arg. #12471
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3120 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3121 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3122
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3123 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3124 var success: bool = false
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3125 def Method(arg = 0)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3126 this.success = true
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3127 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3128 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3129
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3130 class Child extends Base
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3131 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3132 super.Method()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3133 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3134 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3135
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3136 var obj = Child.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3137 assert_equal(true, obj.success)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3138 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3139 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3140 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3141
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3142 def Test_class_import()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3143 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3144 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3145 export class Animal
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3146 var kind: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3147 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3148 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3149 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3150 writefile(lines, 'Xanimal.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3151
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3152 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3153 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3154 import './Xanimal.vim' as animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3155
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3156 var a: animal.Animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3157 a = animal.Animal.new('fish', 'Eric')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3158 assert_equal('fish', a.kind)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3159 assert_equal('Eric', a.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3160
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3161 var b: animal.Animal = animal.Animal.new('cat', 'Garfield')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3162 assert_equal('cat', b.kind)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3163 assert_equal('Garfield', b.name)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3164 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3165 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3166 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3167
34759
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3168 " Test for importing a class into a legacy script and calling the class method
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3169 def Test_class_method_from_legacy_script()
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3170 var lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3171 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3172 export class A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3173 static var name: string = 'a'
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3174 static def SetName(n: string)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3175 name = n
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3176 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3177 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3178 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3179 writefile(lines, 'Xvim9export.vim', 'D')
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3180
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3181 lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3182 import './Xvim9export.vim' as vim9
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3183
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3184 call s:vim9.A.SetName('b')
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3185 call assert_equal('b', s:vim9.A.name)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3186 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3187 v9.CheckScriptSuccess(lines)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3188 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3189
33929
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3190 " Test for implementing an imported interface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3191 def Test_implement_imported_interface()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3192 var lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3193 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3194 export interface Imp_Intf1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3195 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3196 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3197 export interface Imp_Intf2
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3198 def Fn2(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3199 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3200 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3201 writefile(lines, 'Ximportinterface.vim', 'D')
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3202
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3203 lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3204 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3205 import './Ximportinterface.vim' as Xintf
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3206
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3207 class A implements Xintf.Imp_Intf1, Xintf.Imp_Intf2
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3208 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3209 return 10
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3210 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3211 def Fn2(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3212 return 20
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3213 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3214 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3215 var a = A.new()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3216 assert_equal(10, a.Fn1())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3217 assert_equal(20, a.Fn2())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3218 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3219 v9.CheckScriptSuccess(lines)
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3220 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3221
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3222 " Test for extending an imported class
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3223 def Test_extend_imported_class()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3224 var lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3225 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3226 export class Imp_C1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3227 def Fn1(): number
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3228 return 5
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3229 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3230 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3231 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3232 writefile(lines, 'Xextendimportclass.vim', 'D')
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3233
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3234 lines =<< trim END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3235 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3236 import './Xextendimportclass.vim' as XClass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3237
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3238 class A extends XClass.Imp_C1
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3239 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3240 var a = A.new()
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3241 assert_equal(5, a.Fn1())
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3242 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3243 v9.CheckScriptSuccess(lines)
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3244 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3245
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3246 def Test_abstract_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3247 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3248 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3249 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3250 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3251 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3252 class Person extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3253 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3254 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3255 var p: Base = Person.new('Peter', 42)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3256 assert_equal('Peter', p.name)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3257 assert_equal(42, p.age)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3258 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3259 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3260
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3261 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3262 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3263 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3264 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3265 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3266 class Person extends Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3267 var age: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3268 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3269 var p = Base.new('Peter')
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3270 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
3271 v9.CheckSourceFailure(lines, 'E1325: Method "new" not found in class "Base"', 8)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3272
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3273 lines =<< trim END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3274 abstract class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3275 var name: string
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3276 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3277 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3278 v9.CheckSourceFailure(lines, 'E1316: Class can only be defined in Vim9 script', 1)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3279
35062
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3280 # Additional commands after "abstract class"
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3281 lines =<< trim END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3282 vim9script
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3283 abstract class Something | var x = []
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3284 endclass
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3285 END
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3286 v9.CheckSourceFailure(lines, "E488: Trailing characters: | var x = []", 2)
f57990be7526 patch 9.1.0376: Vim9: Trailing commands after class/enum keywords ignored
Christian Brabandt <cb@256bit.org>
parents: 34907
diff changeset
3287
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3288 # Abstract class cannot have a "new" function
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3289 lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3290 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3291 abstract class Base
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3292 def new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3293 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3294 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3295 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3296 v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4)
34759
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3297
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3298 # extending an abstract class with class methods and variables
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3299 lines =<< trim END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3300 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3301 abstract class A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3302 static var s: string = 'vim'
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3303 static def Fn(): list<number>
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3304 return [10]
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3305 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3306 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3307 class B extends A
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3308 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3309 var b = B.new()
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3310 assert_equal('vim', A.s)
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3311 assert_equal([10], A.Fn())
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3312 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3313 v9.CheckScriptSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3314 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3315
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3316 def Test_closure_in_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3317 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3318 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3319
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3320 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3321 var y: list<string> = ['B']
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3322
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3323 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3324 g:result = filter(['A', 'B'], (_, v) => index(this.y, v) == -1)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3325 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3326 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3327
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3328 Foo.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3329 assert_equal(['A'], g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3330 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3331 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3332 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3333
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3334 def Test_construct_object_from_legacy()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3335 # Cannot directly invoke constructor from legacy
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3336 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3337 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3338
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3339 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3340
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3341 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3342 def new(arg: string)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3343 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3344 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3345 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3346
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3347 export def CreateA(...args: list<any>): A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3348 return call(A.new, args)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3349 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3350
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3351 g:P = CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3352 legacy call g:P('some_arg')
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3353 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3354 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3355 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3356 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3357
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3358 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3359 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3360
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3361 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3362
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3363 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3364 static def CreateA(options = {}): any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3365 return A.new()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3366 enddef
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3367 def new()
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3368 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3369 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3370 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3371
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3372 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3373 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3374 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3375 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3376 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3377 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3378
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3379 # This also tests invoking "new()" with "call"
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3380 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3381 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3382
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3383 var createdObject: any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3384
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3385 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3386 var val1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3387 var val2: number
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3388 static def CreateA(...args: list<any>): any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3389 createdObject = call(A.new, args)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3390 return createdObject
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3391 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3392 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3393
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3394 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3395 legacy call g:P(3, 5)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3396 assert_equal(3, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3397 assert_equal(5, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3398 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3399 assert_equal(0, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3400 assert_equal(0, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3401 legacy call g:P(7)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3402 assert_equal(7, createdObject.val1)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3403 assert_equal(0, createdObject.val2)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3404 unlet g:P
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3405 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3406 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3407 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3408
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3409 def Test_defer_with_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3410 var lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3411 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3412
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3413 class CWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3414 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3415 g:result ..= "entered/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3416 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3417 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3418 g:result ..= "exited"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3419 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3420 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3421
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3422 def With(ee: CWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3423 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3424 defer ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3425 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3426 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3427
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3428 g:result = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3429 var obj = CWithEE.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3430 obj->With(() => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3431 g:result ..= "called/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3432 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3433 assert_equal('entered/called/exited', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3434 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3435 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3436 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3437
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3438 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3439 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3440
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3441 class BaseWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3442 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3443 g:result ..= "entered-base/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3444 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3445 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3446 g:result ..= "exited-base"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3447 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3448 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3449
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3450 class CWithEE extends BaseWithEE
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3451 def Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3452 g:result ..= "entered-child/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3453 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3454 def Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3455 g:result ..= "exited-child"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3456 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3457 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3458
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3459 def With(ee: BaseWithEE, F: func)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3460 ee.Enter()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3461 defer ee.Exit()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3462 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3463 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3464
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3465 g:result = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3466 var obj = CWithEE.new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3467 obj->With(() => {
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3468 g:result ..= "called/"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3469 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3470 assert_equal('entered-child/called/exited-child', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3471 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3472 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3473 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3474 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3475
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3476 " The following test used to crash Vim (Github issue #12676)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3477 def Test_extends_method_crashes_vim()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3478 var lines =<< trim END
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3479 vim9script
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3480
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3481 class Observer
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3482 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3483
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3484 class Property
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3485 var value: any
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3486
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3487 def Set(v: any)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3488 if v != this.value
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3489 this.value = v
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3490 endif
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3491 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3492
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3493 def Register(observer: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3494 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3495 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3496
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3497 class Bool extends Property
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3498 var value2: bool
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3499 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3500
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3501 def Observe(obj: Property, who: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3502 obj.Register(who)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3503 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3504
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3505 var p = Bool.new(false)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3506 var myObserver = Observer.new()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3507
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3508 Observe(p, myObserver)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3509
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3510 p.Set(true)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3511 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3512 v9.CheckSourceSuccess(lines)
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3513 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3514
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3515 " Test for calling a method in a class that is extended
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3516 def Test_call_method_in_extended_class()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3517 var lines =<< trim END
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3518 vim9script
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3519
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3520 var prop_init_called = false
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3521 var prop_register_called = false
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3522
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3523 class Property
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3524 def Init()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3525 prop_init_called = true
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3526 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3527
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3528 def Register()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3529 prop_register_called = true
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3530 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3531 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3532
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3533 class Bool extends Property
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3534 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3535
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3536 def Observe(obj: Property)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3537 obj.Register()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3538 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3539
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3540 var p = Property.new()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3541 Observe(p)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3542
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3543 p.Init()
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3544 assert_true(prop_init_called)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3545 assert_true(prop_register_called)
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3546 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3547 v9.CheckSourceSuccess(lines)
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3548 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3549
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3550 def Test_instanceof()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3551 var lines =<< trim END
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3552 vim9script
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3553
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3554 class Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3555 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3556
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3557 class Base2 extends Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3558 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3559
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3560 interface Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3561 endinterface
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3562
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3563 class Mix1 implements Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3564 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3565
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3566 class Base3 extends Mix1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3567 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3568
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3569 type AliasBase1 = Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3570 type AliasBase2 = Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3571 type AliasIntf1 = Intf1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3572 type AliasMix1 = Mix1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3573
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3574 var b1 = Base1.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3575 var b2 = Base2.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3576 var b3 = Base3.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3577
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3578 assert_true(instanceof(b1, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3579 assert_true(instanceof(b2, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3580 assert_false(instanceof(b1, Base2))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3581 assert_true(instanceof(b3, Mix1))
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3582 assert_true(instanceof(b3, Base1, Base2, Intf1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3583
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3584 assert_true(instanceof(b1, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3585 assert_true(instanceof(b2, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3586 assert_false(instanceof(b1, AliasBase2))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3587 assert_true(instanceof(b3, AliasMix1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3588 assert_true(instanceof(b3, AliasBase1, AliasBase2, AliasIntf1))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3589
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3590 def Foo()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3591 var a1 = Base1.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3592 var a2 = Base2.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3593 var a3 = Base3.new()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3594
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3595 assert_true(instanceof(a1, Base1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3596 assert_true(instanceof(a2, Base1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3597 assert_false(instanceof(a1, Base2))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3598 assert_true(instanceof(a3, Mix1))
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3599 assert_true(instanceof(a3, Base1, Base2, Intf1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3600
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3601 assert_true(instanceof(a1, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3602 assert_true(instanceof(a2, AliasBase1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3603 assert_false(instanceof(a1, AliasBase2))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3604 assert_true(instanceof(a3, AliasMix1))
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3605 assert_true(instanceof(a3, AliasBase1, AliasBase2, AliasIntf1))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3606 enddef
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3607 Foo()
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3608
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3609 var o_null: Base1
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3610 assert_false(instanceof(o_null, Base1))
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3611
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3612 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3613 v9.CheckSourceSuccess(lines)
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3614
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3615 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3616 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3617
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3618 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3619 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3620 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3621 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3622 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof')
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3623
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3624 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3625 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3626
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3627 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3628 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3629 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3630 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3631 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3632 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3633 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3634 v9.CheckSourceFailure(lines, 'E119: Not enough arguments for function: instanceof')
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3635
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3636 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3637 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3638
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3639 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3640 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3641
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3642 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3643 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3644
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3645 var o = Base2.new()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3646 instanceof(o, Base1, Base2, 3)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3647 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3648 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4', 10)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3649
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3650 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3651 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3652
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3653 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3654 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3655
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3656 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3657 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3658
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3659 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3660 var o = Base2.new()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3661 instanceof(o, Base1, Base2, 3)
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3662 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3663 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3664 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3665 v9.CheckSourceFailure(lines, 'E693: Class or class typealias required for argument 4')
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3666 enddef
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3667
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3668 " Test for calling a method in the parent class that is extended partially.
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3669 " This used to fail with the 'E118: Too many arguments for function: Text' error
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3670 " message (Github issue #12524).
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3671 def Test_call_method_in_parent_class()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3672 var lines =<< trim END
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3673 vim9script
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3674
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3675 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3676 var _lnum: number = 1
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3677
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3678 def SetY(lnum: number)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3679 this._lnum = lnum
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3680 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3681
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3682 def Text(): string
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3683 return ''
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3684 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3685 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3686
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3687 class Foo extends Widget
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3688 def Text(): string
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3689 return '<Foo>'
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3690 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3691 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3692
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3693 def Stack(w1: Widget, w2: Widget): list<Widget>
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3694 w1.SetY(1)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3695 w2.SetY(2)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3696 return [w1, w2]
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3697 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3698
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3699 var foo1 = Foo.new()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3700 var foo2 = Foo.new()
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3701 var l = Stack(foo1, foo2)
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3702 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3703 v9.CheckSourceSuccess(lines)
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3704 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3705
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3706 " Test for calling methods from three levels of classes
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3707 def Test_multi_level_method_call()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3708 var lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3709 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3710
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3711 var A_func1: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3712 var A_func2: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3713 var A_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3714 var B_func2: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3715 var B_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3716 var C_func3: number = 0
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3717
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3718 class A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3719 def Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3720 A_func1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3721 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3722
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3723 def Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3724 A_func2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3725 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3726
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3727 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3728 A_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3729 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3730 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3731
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3732 class B extends A
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3733 def Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3734 B_func2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3735 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3736
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3737 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3738 B_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3739 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3740 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3741
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3742 class C extends B
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3743 def Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3744 C_func3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3745 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3746 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3747
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3748 def A_CallFuncs(a: A)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3749 a.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3750 a.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3751 a.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3752 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3753
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3754 def B_CallFuncs(b: B)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3755 b.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3756 b.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3757 b.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3758 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3759
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3760 def C_CallFuncs(c: C)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3761 c.Func1()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3762 c.Func2()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3763 c.Func3()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3764 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3765
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3766 var cobj = C.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3767 A_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3768 B_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3769 C_CallFuncs(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3770 assert_equal(3, A_func1)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3771 assert_equal(0, A_func2)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3772 assert_equal(0, A_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3773 assert_equal(3, B_func2)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3774 assert_equal(0, B_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3775 assert_equal(3, C_func3)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3776 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3777 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3778 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3779
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3780 " Test for using members from three levels of classes
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3781 def Test_multi_level_member_access()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3782 var lines =<< trim END
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3783 vim9script
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3784
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3785 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3786 public var val1: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3787 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3788
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3789 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3790 public var val2: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3791 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3792
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3793 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3794 public var val3: number = 0
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3795 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3796
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3797 def A_members(a: A)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3798 a.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3799 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3800
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3801 def B_members(b: B)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3802 b.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3803 b.val2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3804 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3805
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3806 def C_members(c: C)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3807 c.val1 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3808 c.val2 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3809 c.val3 += 1
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3810 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3811
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3812 var cobj = C.new()
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3813 A_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3814 B_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3815 C_members(cobj)
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3816 assert_equal(3, cobj.val1)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3817 assert_equal(2, cobj.val2)
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3818 assert_equal(1, cobj.val3)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3819 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3820 v9.CheckSourceSuccess(lines)
32854
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3821 enddef
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3822
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3823 " Test expansion of <stack> with class methods.
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3824 def Test_stack_expansion_with_methods()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3825 var lines =<< trim END
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3826 vim9script
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3827
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3828 class C
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3829 def M1()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3830 F0()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3831 enddef
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3832 endclass
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3833
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3834 def F0()
34755
1a411f737239 patch 9.1.0255: Vim9: no indication of script nr in stack trace of classes
Christian Brabandt <cb@256bit.org>
parents: 34748
diff changeset
3835 assert_match('<SNR>\d\+_F\[1\]\.\.<SNR>\d\+_C\.M1\[1\]\.\.<SNR>\d\+_F0\[1\]$', expand('<stack>'))
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3836 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3837
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3838 def F()
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3839 C.new().M1()
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3840 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3841
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3842 F()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3843 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3844 v9.CheckSourceSuccess(lines)
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3845 enddef
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3846
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3847 " Test the return type of the new() constructor
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3848 def Test_new_return_type()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3849 # new() uses the default return type and there is no return statement
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3850 var lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3851 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3852
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3853 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3854 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3855
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3856 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3857 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3858 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3859 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3860 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3861 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3862
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3863 var c = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3864 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3865
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3866 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3867 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3868 assert_equal('object<C>', typename(v1))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3869
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3870 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3871 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3872 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3873 assert_equal('object<C>', typename(v2))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3874 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3875 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3876 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3877 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3878
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3879 # new() uses the default return type and an empty 'return' statement
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3880 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3881 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3882
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3883 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3884 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3885
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3886 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3887 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3888 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3889 return
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3890 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3891 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3892 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3893
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3894 var c = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3895 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3896
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3897 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3898 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3899 assert_equal('object<C>', typename(v1))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3900
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3901 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3902 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3903 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3904 assert_equal('object<C>', typename(v2))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3905 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3906 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3907 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3908 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3909
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3910 # new() uses "any" return type and returns "this"
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3911 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3912 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3913
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3914 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3915 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3916
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3917 def new(this._bufnr): any
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3918 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3919 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3920 return this
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3921 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3922 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3923 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3924 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3925 v9.CheckSourceFailure(lines, 'E1365: Cannot use a return type with the "new" method', 11)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3926
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3927 # new() uses 'Dict' return type and returns a Dict
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3928 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3929 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3930
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3931 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3932 var _state: dict<any>
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3933
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3934 def new(): dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3935 this._state = {}
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3936 return this._state
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3937 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3938 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3939
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3940 var c = C.new()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3941 assert_equal('object<C>', typename(c))
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3942 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3943 v9.CheckSourceFailure(lines, 'E1365: Cannot use a return type with the "new" method', 9)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3944 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3945
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3946 " Test for checking a member initialization type at run time.
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3947 def Test_runtime_type_check_for_member_init()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3948 var lines =<< trim END
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3949 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3950
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3951 var retnum: bool = false
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3952
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3953 def F(): any
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3954 retnum = !retnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3955 if retnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3956 return 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3957 else
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3958 return "hello"
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3959 endif
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3960 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3961
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3962 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3963 var _foo: bool = F()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3964 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3965
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3966 var c1 = C.new()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3967 var c2 = C.new()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3968 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3969 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected bool but got string', 0)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3970 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3971
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3972 " Test for locking a variable referring to an object and reassigning to another
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3973 " object.
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3974 def Test_lockvar_object()
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3975 var lines =<< trim END
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3976 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3977
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3978 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3979 var val: number
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3980 def new(this.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3981 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3982 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3983
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3984 var some_dict: dict<C> = { a: C.new(1), b: C.new(2), c: C.new(3), }
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3985 lockvar 2 some_dict
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3986
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3987 var current: C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3988 current = some_dict['c']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3989 assert_equal(3, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3990 current = some_dict['b']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3991 assert_equal(2, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3992
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3993 def F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3994 current = some_dict['c']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3995 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3996
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3997 def G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3998 current = some_dict['b']
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3999 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4000
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4001 F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4002 assert_equal(3, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4003 G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4004 assert_equal(2, current.val)
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4005 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4006 v9.CheckSourceSuccess(lines)
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4007 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
4008
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4009 " Test trying to lock an object variable from various places
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4010 def Test_lockvar_object_variable()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4011 # An object variable lockvar has several cases:
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4012 # object method, scriptlevel, scriplevel from :def, :def arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4013 # method arg, static method arg.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4014 # Also different depths
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4015
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4016 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4017 # lockvar of read-only object variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4018 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4019
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4020 # read-only lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4021 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4022 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4023
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4024 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4025 var val1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4026 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4027 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4028 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4029 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4030 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4031 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4032 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4033 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "this.val1" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4034
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4035 # read-only lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4036 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4037 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4038
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4039 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4040 var val2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4041 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4042 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4043 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4044 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4045 v9.CheckSourceFailure(lines, 'E1335: Variable "val2" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4046
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4047 # read-only lockvar of scriptlevel variable from def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4048 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4049 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4050
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4051 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4052 var val3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4053 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4054 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4055 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4056 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4057 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4058 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4059 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4060 v9.CheckSourceFailure(lines, 'E1335: Variable "val3" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4061
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4062 # read-only lockvar of def argument variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4063 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4064 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4065
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4066 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4067 var val4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4068 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4069 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4070 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4071 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4072 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4073 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4074 v9.CheckSourceFailure(lines, 'E1335: Variable "val4" in class "C" is not writable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4075
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4076 # TODO: the following tests use type "any" for argument. Need a run time
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4077 # check for access. Probably OK as is for now.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4078
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4079 # read-only lockvar from object method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4080 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4081 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4082
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4083 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4084 var val5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4085 def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4086 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4087 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4088 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4089 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4090 o.Lock(C.new(5))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4091 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4092 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4093
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4094 # read-only lockvar from class method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4095 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4096 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4097
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4098 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4099 var val6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4100 static def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4101 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4102 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4103 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4104 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4105 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4106 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4107 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4108
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4109 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4110 # lockvar of public object variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4111 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4112
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4113 # lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4114 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4115 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4116
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4117 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4118 public var val1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4119 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4120 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4121 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4122 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4123 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4124 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4125 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4126 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "this.val1" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4127
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4128 # lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4129 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4130 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4131
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4132 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4133 public var val2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4134 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4135 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4136 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4137 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4138 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val2" in class "C"', 7)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4139
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4140 # lockvar of scriptlevel variable from def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4141 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4142 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4143
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4144 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4145 public var val3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4146 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4147 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4148 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4149 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4150 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4151 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4152 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4153 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val3" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4154
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4155 # lockvar of def argument variable
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4156 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4157 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4158
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4159 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4160 public var val4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4161 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4162 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4163 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4164 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4165 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4166 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4167 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o.val4" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4168
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4169 # lockvar from object method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4170 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4171 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4172
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4173 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4174 public var val5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4175 def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4176 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4177 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4178 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4179 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4180 o.Lock(C.new(5))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4181 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4182 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val5" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4183
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4184 # lockvar from class method arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4185 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4186 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4187
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4188 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4189 public var val6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4190 static def Lock(o_any: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4191 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4192 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4193 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4194 var o = C.new(3)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4195 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4196 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4197 v9.CheckSourceFailure(lines, 'E1391: Cannot (un)lock variable "o_any.val6" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4198 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4199
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4200 " Test trying to lock a class variable from various places
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4201 def Test_lockvar_class_variable()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4202
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4203 # lockvar bare static from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4204 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4205 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4206
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4207 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4208 public static var sval1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4209 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4210 lockvar sval1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4211 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4212 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4213 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4214 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4215 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4216 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval1" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4217
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4218 # lockvar C.static from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4219 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4220 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4221
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4222 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4223 public static var sval2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4224 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4225 lockvar C.sval2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4226 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4227 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4228 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4229 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4230 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4231 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval2" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4232
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4233 # lockvar bare static from class method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4234 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4235 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4236
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4237 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4238 public static var sval3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4239 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4240 lockvar sval3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4241 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4242 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4243 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4244 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4245 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval3" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4246
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4247 # lockvar C.static from class method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4248 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4249 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4250
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4251 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4252 public static var sval4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4253 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4254 lockvar C.sval4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4255 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4256 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4257 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4258 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4259 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval4" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4260
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4261 # lockvar C.static from script level
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4262 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4263 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4264
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4265 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4266 public static var sval5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4267 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4268 lockvar C.sval5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4269 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4270 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "C.sval5" in class "C"', 6)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4271
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4272 # lockvar o.static from script level
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4273 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4274 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4275
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4276 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4277 public static var sval6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4278 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4279 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4280 lockvar o.sval6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4281 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4282 v9.CheckSourceFailure(lines, 'E1375: Class variable "sval6" accessible only using class "C"', 7)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4283 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4284
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4285 " Test locking an argument to :def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4286 def Test_lockvar_argument()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4287 # Lockvar a function arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4288 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4289 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4290
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4291 def Lock(val: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4292 lockvar val
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4293 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4294
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4295 var d = {a: 1, b: 2}
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4296 Lock(d)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4297
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4298 d->extend({c: 3})
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4299 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4300 v9.CheckSourceFailure(lines, 'E741: Value is locked: extend() argument')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4301
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4302 # Lockvar a function arg. Verify "sval" is interpreted as argument and not a
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4303 # class member in "C". This tests lval_root_is_arg.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4304 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4305 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4306
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4307 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4308 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4309 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4310
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4311 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4312 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4313 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4314
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4315 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4316 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4317 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4318 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4319
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4320 # Lock a class.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4321 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4322 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4323
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4324 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4325 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4326 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4327
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4328 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4329 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4330 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4331
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4332 Lock2(C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4333 END
33936
bdd408288d95 patch 9.0.2164: Vim9: can use type a func arg/return value
Christian Brabandt <cb@256bit.org>
parents: 33933
diff changeset
4334 v9.CheckSourceFailure(lines, 'E1405: Class "C" cannot be used as a value')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4335
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4336 # Lock an object.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4337 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4338 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4339
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4340 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4341 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4342 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4343
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4344 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4345 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4346 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4347
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4348 Lock2(C.new())
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4349 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4350 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4351
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4352 # In this case (unlike previous) "lockvar sval" is a class member.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4353 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4354 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4355
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4356 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4357 public static var sval: list<number>
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4358 def Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4359 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4360 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4361 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4362
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4363
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4364 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4365 o.Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4366 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4367 v9.CheckSourceFailure(lines, 'E1392: Cannot (un)lock class variable "sval" in class "C"', 1)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4368 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4369
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4370 " Test that this can be locked without error
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4371 def Test_lockvar_this()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4372 # lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4373 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4374 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4375 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4376 def TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4377 lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4378 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4379 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4380 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4381 o.TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4382 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4383 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4384
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4385 # lockvar four (four letter word, but not this)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4386 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4387 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4388 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4389 def TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4390 var four: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4391 lockvar four
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4392 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4393 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4394 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4395 o.TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4396 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4397 v9.CheckSourceFailure(lines, 'E1178: Cannot lock or unlock a local variable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4398
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4399 # lockvar this5; "this" + one char, 5 letter word, starting with "this"
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4400 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4401 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4402 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4403 def TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4404 var this5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4405 lockvar this5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4406 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4407 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4408 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4409 o.TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4410 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4411 v9.CheckSourceFailure(lines, 'E1178: Cannot lock or unlock a local variable')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4412 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4413
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4414 " Test some general lockvar cases
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4415 def Test_lockvar_general()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4416 # lockvar an object and a class. It does nothing
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4417 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4418 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4419 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4420 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4421 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4422 lockvar o
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4423 lockvar C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4424 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4425 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4426
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4427 # Lock a list element that's nested in an object variable from a :def
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4428 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4429 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4430
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4431 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4432 public var val: list<list<number>> = [ [1], [2], [3] ]
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4433 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4434 def Lock2(obj: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4435 lockvar obj.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4436 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4437
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4438 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4439 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4440 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4441 assert_equal([ [9], [2], [3] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4442 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4443 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4444 call assert_false(true, 'assign should have failed')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4445 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4446 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4447 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4448 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4449 assert_equal([ [9], [2], [8] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4450 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4451 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4452
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4453 # Lock a list element that's nested in an object variable from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4454 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4455 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4456
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4457 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4458 public var val: list<list<number>> = [ [1], [2], [3] ]
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4459 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4460
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4461 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4462 lockvar o.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4463 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4464 assert_equal([ [9], [2], [3] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4465 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4466 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4467 call assert_false(true, 'assign should have failed')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4468 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4469 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4470 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4471 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4472 assert_equal([ [9], [2], [8] ], o.val)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4473 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4474 v9.CheckSourceSuccess(lines)
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4475
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4476 # lock a script level variable from an object method
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4477 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4478 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4479
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4480 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4481 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4482 lockvar l
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4483 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4484 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4485
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4486 var l = [1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4487 C.new().Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4488 l[0] = 11
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4489 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4490 v9.CheckSourceFailure(lines, 'E741: Value is locked: l[0] = 11', 11)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4491
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4492 # lock a list element referenced by a protected object variable
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4493 # in an object fetched via a script level list
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4494 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4495 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4496
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4497 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4498 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4499 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4500 lockvar lc[0]._v1[1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4501 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4502 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4503
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4504 var l = [[1], [2], [3]]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4505 var o = C.new(l)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4506 var lc: list<C> = [ o ]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4507
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4508 o.Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4509 l[0] = [22]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4510 l[1] = [33]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4511 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4512 v9.CheckSourceFailure(lines, 'E741: Value is locked: l[1] = [33]', 16)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4513
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4514 # similar to the previous test, except the locking code is executing
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4515 # in a class that does not own the protected variable.
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4516 # Note that the locking code is in a class has a protected variable of
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4517 # the same name.
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4518 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4519 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4520
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4521 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4522 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4523 def Lock(obj: any)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4524 lockvar lc[0]._v1[1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4525 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4526 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4527
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4528 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4529 var _v1: list<list<number>>
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4530 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4531
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4532 var l = [[1], [2], [3]]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4533 var o = C.new(l)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4534 var lc: list<C> = [ o ]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4535
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4536 var o2 = C2.new()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4537 o2.Lock(o)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4538 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4539 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_v1" in class "C"')
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4540 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4541
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4542 " Test builtin islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4543 def Test_lockvar_islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4544 # Can't lock class/object variable
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4545 # Lock class/object variable's value
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
4546 # Lock item of variable's value (a list item)
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
4547 # variable is at index 1 within class/object
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4548 var lines =<< trim END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4549 vim9script
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4550
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4551 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4552 var o0: list<list<number>> = [ [0], [1], [2]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4553 var o1: list<list<number>> = [[10], [11], [12]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4554 static var c0: list<list<number>> = [[20], [21], [22]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4555 static var c1: list<list<number>> = [[30], [31], [32]]
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4556 endclass
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4557
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4558 def LockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4559 lockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4560 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4561
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4562 def UnlockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4563 unlockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4564 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4565
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4566 var obj = C.new()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4567 #lockvar obj.o1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4568
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4569 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4570 lockvar obj.o1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4571 call assert_false(1, '"lockvar obj.o1" should have failed')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4572 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4573 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4574 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4575
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4576 LockIt(obj.o1) # but can lock it's value
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4577 assert_equal(1, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4578 assert_equal(1, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4579 assert_equal(1, islocked("obj.o1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4580 UnlockIt(obj.o1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4581 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4582 assert_equal(0, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4583
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4584 lockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4585 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4586 assert_equal(1, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4587 assert_equal(0, islocked("obj.o1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4588 unlockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4589 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4590 assert_equal(0, islocked("obj.o1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4591
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4592 # Same thing, but with a static
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4593
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4594 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4595 lockvar C.c1 # can't lock something you can't write to
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4596 call assert_false(1, '"lockvar C.c1" should have failed')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4597 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4598 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4599 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4600
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4601 LockIt(C.c1) # but can lock it's value
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4602 assert_equal(1, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4603 assert_equal(1, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4604 assert_equal(1, islocked("C.c1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4605 UnlockIt(C.c1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4606 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4607 assert_equal(0, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4608
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4609 lockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4610 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4611 assert_equal(1, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4612 assert_equal(0, islocked("C.c1[1]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4613 unlockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4614 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4615 assert_equal(0, islocked("C.c1[0]"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4616 END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4617 v9.CheckSourceSuccess(lines)
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4618
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4619 # Do islocked() from an object method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4620 # and then from a class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4621 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4622 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4623
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4624 var l0o0 = [ [0], [1], [2]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4625 var l0o1 = [ [10], [11], [12]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4626 var l0c0 = [[120], [121], [122]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4627 var l0c1 = [[130], [131], [132]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4628
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4629 class C0
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4630 var o0: list<list<number>> = l0o0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4631 var o1: list<list<number>> = l0o1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4632 static var c0: list<list<number>> = l0c0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4633 static var c1: list<list<number>> = l0c1
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4634 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4635 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4636 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4637 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4638 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4639 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4640 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4641
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4642 var l2o0 = [[20000], [20001], [20002]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4643 var l2o1 = [[20010], [20011], [20012]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4644 var l2c0 = [[20120], [20121], [20122]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4645 var l2c1 = [[20130], [20131], [20132]]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4646
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4647 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4648 var o0: list<list<number>> = l2o0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4649 var o1: list<list<number>> = l2o1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4650 static var c0: list<list<number>> = l2c0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4651 static var c1: list<list<number>> = l2c1
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4652 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4653 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4654 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4655 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4656 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4657 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4658 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4659
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4660 var obj0 = C0.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4661 var obj2 = C2.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4662
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4663 var l = [ obj0, null_object, obj2 ]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4664
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4665 # lock list, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4666 assert_equal(0, obj0.Islocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4667 assert_equal(0, obj0.Islocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4668 lockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4669 assert_equal(1, obj0.Islocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4670 assert_equal(1, obj0.Islocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4671
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4672 #echo "check-b" obj2.Islocked("l[1].o1") # NULL OBJECT
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4673
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4674 # lock list element, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4675 lockvar l0o1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4676 assert_equal(0, obj0.Islocked("this.o1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4677 assert_equal(1, obj0.Islocked("this.o1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4678
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4679 assert_equal(0, obj0.Islocked("this.o1"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4680 lockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4681 assert_equal(1, obj0.Islocked("this.o1"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4682 unlockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4683
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4684 lockvar l0c1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4685
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4686 # static by class name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4687 assert_equal(0, obj0.Islocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4688 assert_equal(1, obj0.Islocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4689 # static by bare name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4690 assert_equal(0, obj0.Islocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4691 assert_equal(1, obj0.Islocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4692
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4693 # static by class name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4694 assert_equal(0, obj2.Islocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4695 assert_equal(1, obj2.Islocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4696 # static by bare name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4697 assert_equal(0, obj2.Islocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4698 assert_equal(0, obj2.Islocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4699
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4700
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4701 # static by bare name in same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4702 assert_equal(0, obj0.Islocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4703 lockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4704 assert_equal(1, obj0.Islocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4705
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4706 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4707 # similar stuff, but use static method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4708 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4709
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4710 unlockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4711
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4712 # lock list, object func access through script var expr
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4713 assert_equal(0, C0.SIslocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4714 assert_equal(0, C0.SIslocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4715 lockvar l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4716 assert_equal(1, C0.SIslocked("l[0].o0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4717 assert_equal(1, C0.SIslocked("l[0].o0[2]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4718
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4719 unlockvar l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4720
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4721 # can't access "this" from class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4722 try
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4723 C0.SIslocked("this.o1[0]")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4724 call assert_0(1, '"C0.SIslocked("this.o1[0]")" should have failed')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4725 catch
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4726 call assert_exception('E121: Undefined variable: this')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4727 endtry
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4728
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4729 lockvar l0c1[1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4730
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4731 # static by class name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4732 assert_equal(0, C0.SIslocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4733 assert_equal(1, C0.SIslocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4734 # static by bare name member expr from same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4735 assert_equal(0, C0.SIslocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4736 assert_equal(1, C0.SIslocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4737
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4738 # static by class name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4739 assert_equal(0, C2.SIslocked("C0.c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4740 assert_equal(1, C2.SIslocked("C0.c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4741 # static by bare name member expr from other class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4742 assert_equal(0, C2.SIslocked("c1[0]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4743 assert_equal(0, C2.SIslocked("c1[1]"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4744
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4745
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4746 # static by bare name in same class
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4747 unlockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4748 assert_equal(0, C0.SIslocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4749 lockvar l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4750 assert_equal(1, C0.SIslocked("c0"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4751 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4752 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4753
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4754 # Check islocked class/object from various places.
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4755 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4756 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4757
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4758 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4759 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4760 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4761 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4762 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4763 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4764 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4765 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4766 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4767
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4768 # object method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4769 assert_equal(0, obj.Islocked("this"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4770 assert_equal(0, obj.Islocked("C"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4771
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4772 # class method
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4773 ### assert_equal(0, C.SIslocked("this"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4774 assert_equal(0, C.SIslocked("C"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4775
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4776 #script level
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4777 var v: number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4778 v = islocked("C")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4779 assert_equal(0, v)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4780 v = islocked("obj")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4781 assert_equal(0, v)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4782 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4783 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4784 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4785
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4786 def Test_lockvar_islocked_notfound()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4787 # Try non-existent things
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4788 var lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4789 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4790
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4791 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4792 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4793 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4794 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4795 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4796 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4797 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4798 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4799 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4800 assert_equal(-1, obj.Islocked("anywhere"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4801 assert_equal(-1, C.SIslocked("notanywhere"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4802 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4803 v9.CheckSourceSuccess(lines)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4804
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4805 # Something not found of the form "name1.name2" is an error
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4806 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4807 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4808
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4809 islocked("one.two")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4810 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4811 v9.CheckSourceFailure(lines, 'E121: Undefined variable: one')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4812
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4813 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4814 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4815
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4816 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4817 var val = { key: "value" }
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4818 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4819 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4820 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4821 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4822 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4823 obj.Islocked("this.val.not_there"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4824 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4825 v9.CheckSourceFailure(lines, 'E716: Key not present in Dictionary: "not_there"')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4826
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4827 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4828 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4829
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4830 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4831 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4832 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4833 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4834 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4835 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4836 obj.Islocked("this.notobjmember")
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4837 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
4838 v9.CheckSourceFailure(lines, 'E1326: Variable "notobjmember" not found in object "C"')
33532
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4839
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4840 # access a script variable through methods
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4841 lines =<< trim END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4842 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4843
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4844 var l = [1]
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4845 class C
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4846 def Islocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4847 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4848 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4849 static def SIslocked(arg: string): number
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4850 return islocked(arg)
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4851 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4852 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4853 var obj = C.new()
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4854 assert_equal(0, obj.Islocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4855 assert_equal(0, C.SIslocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4856 lockvar l
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4857 assert_equal(1, obj.Islocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4858 assert_equal(1, C.SIslocked("l"))
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4859 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4860 v9.CheckSourceSuccess(lines)
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4861 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4862
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4863 " Test for a protected object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4864 def Test_private_object_method()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4865 # Try calling a protected method using an object (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4866 var lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4867 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4868
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4869 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4870 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4871 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4872 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4873 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4874 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4875 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4876 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4877 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 9)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4878
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4879 # Try calling a protected method using an object (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4880 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4881 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4882
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4883 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4884 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4885 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4886 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4887 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4888 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4889 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4890 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4891 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4892 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4893 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4894 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4895
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4896 # Use a protected method from another object method (in script context)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4897 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4898 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4899
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4900 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4901 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4902 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4903 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4904 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4905 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4906 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4907 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4908 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4909 assert_equal(1234, a.Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4910 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4911 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4912
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4913 # Use a protected method from another object method (def function context)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4914 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4915 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4916
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4917 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4918 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4919 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4920 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4921 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4922 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4923 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4924 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4925 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4926 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4927 assert_equal(1234, a.Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4928 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4929 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4930 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4931 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4932
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4933 # Try calling a protected method without the "this" prefix
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4934 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4935 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4936
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4937 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4938 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4939 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4940 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4941 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4942 return _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4943 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4944 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4945 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4946 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4947 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4948 v9.CheckSourceFailure(lines, 'E117: Unknown function: _Foo', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4949
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4950 # Try calling a protected method using the class name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4951 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4952 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4953
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4954 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4955 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4956 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4957 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4958 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4959 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4960 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4961 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 8)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4962
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4963 # Define two protected methods with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4964 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4965 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4966
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4967 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4968 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4969 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4970 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4971 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4972 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4973 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4974 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4975 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4976
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4977 # Define a protected method and a object method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4978 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4979 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4980
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4981 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4982 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4983 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4984 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4985 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4986 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4987 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4988 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4989 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4990
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4991 # Define an object method and a protected method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4992 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4993 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4994
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4995 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4996 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4997 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4998 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4999 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5000 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5001 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5002 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5003 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5004
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5005 # Call a public method and a protected method from a protected method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5006 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5007 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5008
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5009 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5010 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5011 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5012 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5013 def _Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5014 return 200
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5015 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5016 def _Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5017 assert_equal(100, this.Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5018 assert_equal(200, this._Bar())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5019 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5020 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5021 this._Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5022 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5023 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5024 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5025 a.T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5026 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5027 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5028
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5029 # Try calling a protected method from another class
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5030 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5031 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5032
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5033 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5034 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5035 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5036 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5037 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5038 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5039 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5040 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5041 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5042 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5043 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5044 var b = B.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5045 b.Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5046 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5047 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5048
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5049 # Call a protected object method from a child class object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5050 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5051 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5052 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5053 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5054 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5055 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5056 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5057 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5058 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5059 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5060 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5061 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5062 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5063 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5064 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5065 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5066 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5067 assert_equal(1234, c.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5068 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5069 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5070
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5071 # Call a protected object method from a child class object
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5072 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5073 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5074 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5075 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5076 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5077 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5078 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5079 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5080 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5081 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5082 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5083 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5084 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5085 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5086 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5087 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5088 assert_equal(1234, c._Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5089 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5090 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5091
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5092 # Using "_" prefix in a method name should fail outside of a class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5093 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5094 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5095 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5096 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5097 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5098 var a = _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5099 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5100 v9.CheckSourceFailure(lines, 'E1267: Function name must start with a capital: _Foo(): number', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5101 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5102
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5103 " Test for an protected class method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5104 def Test_private_class_method()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5105 # Try calling a class protected method (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5106 var lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5107 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5108
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5109 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5110 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5111 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5112 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5113 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5114 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5115 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5116 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 8)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5117
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5118 # Try calling a class protected method (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5119 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5120 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5121
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5122 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5123 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5124 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5125 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5126 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5127 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5128 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5129 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5130 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5131 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5132 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5133
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5134 # Try calling a class protected method using an object (at the script level)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5135 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5136 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5137
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5138 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5139 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5140 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5141 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5142 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5143 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5144 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5145 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5146 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 9)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5147
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5148 # Try calling a class protected method using an object (from a def function)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5149 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5150 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5151
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5152 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5153 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5154 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5155 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5156 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5157 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5158 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5159 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5160 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5161 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5162 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5163 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5164
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5165 # Use a class protected method from an object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5166 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5167 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5168
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5169 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5170 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5171 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5172 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5173 def Bar()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5174 assert_equal(1234, _Foo())
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5175 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5176 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5177 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5178 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5179 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5180 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5181
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5182 # Use a class protected method from another class protected method without the
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5183 # class name prefix.
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5184 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5185 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5186
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5187 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5188 static def _Foo1(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5189 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5190 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5191 static def _Foo2()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5192 assert_equal(1234, _Foo1())
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5193 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5194 def Bar()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
5195 _Foo2()
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5196 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5197 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5198 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5199 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5200 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5201 v9.CheckSourceSuccess(lines)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5202
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5203 # Declare a class method and a class protected method with the same name
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5204 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5205 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5206
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5207 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5208 static def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5209 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5210 static def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5211 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5212 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5213 var a = A.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5214 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5215 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 7)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5216
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5217 # Try calling a class protected method from another class
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5218 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5219 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5220
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5221 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5222 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5223 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5224 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5225 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5226 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5227 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5228 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5229 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5230 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5231 var b = B.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5232 assert_equal(1234, b.Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5233 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5234 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5235
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5236 # Call a protected class method from a child class object method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5237 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5238 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5239 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5240 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5241 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5242 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5243 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5244 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5245 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5246 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5247 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5248 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5249 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5250 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5251 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5252 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5253 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5254 assert_equal(1234, c.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5255 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5256 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5257
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5258 # Call a protected class method from a child class protected class method
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5259 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5260 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5261 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5262 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5263 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5264 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5265 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5266 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5267 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5268 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5269 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5270 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5271 static def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5272 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5273 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5274 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5275 assert_equal(1234, C.Baz())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5276 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5277 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo()', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5278
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5279 # Call a protected class method from a child class object
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5280 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5281 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5282 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5283 static def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5284 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5285 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5286 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5287 class B extends A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5288 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5289 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5290 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5291 class C extends B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5292 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5293 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5294 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5295 var c = C.new()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5296 assert_equal(1234, C._Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5297 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5298 v9.CheckSourceFailure(lines, 'E1325: Method "_Foo" not found in class "C"', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5299 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5300
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5301 " Test for using the return value of a class/object method as a function
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5302 " argument.
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5303 def Test_objmethod_funcarg()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5304 var lines =<< trim END
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5305 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5306
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5307 class C
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5308 def Foo(): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5309 return 'foo'
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5310 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5311 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5312
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5313 def Bar(a: number, s: string): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5314 return s
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5315 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5316
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5317 def Baz(c: C)
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5318 assert_equal('foo', Bar(10, c.Foo()))
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5319 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5320
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5321 var t = C.new()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5322 Baz(t)
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5323 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5324 v9.CheckSourceSuccess(lines)
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5325
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5326 lines =<< trim END
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5327 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5328
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5329 class C
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5330 static def Foo(): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5331 return 'foo'
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5332 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5333 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5334
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5335 def Bar(a: number, s: string): string
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5336 return s
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5337 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5338
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5339 def Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5340 assert_equal('foo', Bar(10, C.Foo()))
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5341 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5342
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5343 Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5344 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5345 v9.CheckSourceSuccess(lines)
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5346 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5347
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5348 def Test_static_inheritence()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5349 # subclasses get their own static copy
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5350 var lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5351 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5352
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5353 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5354 static var _svar: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5355 var _mvar: number
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5356 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5357 _svar = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5358 this._mvar = 101
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5359 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5360 def AccessObject(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5361 return this._mvar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5362 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5363 def AccessStaticThroughObject(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5364 return _svar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5365 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5366 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5367
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5368 class B extends A
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5369 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5370 this._mvar = 102
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5371 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5372 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5373
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5374 class C extends B
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5375 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5376 this._mvar = 103
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5377 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5378
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5379 def AccessPrivateStaticThroughClassName(): number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5380 assert_equal(1, A._svar)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5381 return 444
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5382 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5383 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5384
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5385 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5386 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5387 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5388 assert_equal(101, oa.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5389 assert_equal(102, ob.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5390 assert_equal(103, oc.AccessObject())
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5391
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5392 assert_fails('echo oc.AccessPrivateStaticThroughClassName()', 'E1333: Cannot access protected variable "_svar" in class "A"')
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5393
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5394 # verify object properly resolves to correct static
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5395 assert_equal(1, oa.AccessStaticThroughObject())
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5396 assert_equal(1, ob.AccessStaticThroughObject())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5397 assert_equal(1, oc.AccessStaticThroughObject())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5398 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5399 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5400 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5401
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5402 " Test for declaring duplicate object and class members
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5403 def Test_dup_member_variable()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5404 # Duplicate member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5405 var lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5406 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5407 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5408 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5409 var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5410 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5411 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5412 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5413
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5414 # Duplicate protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5415 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5416 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5417 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5418 var _val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5419 var _val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5420 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5421 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5422 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5423
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5424 # Duplicate public member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5425 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5426 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5427 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5428 public var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5429 public var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5430 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5431 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5432 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5433
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5434 # Duplicate protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5435 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5436 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5437 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5438 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5439 var _val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5440 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5441 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5442 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5443
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5444 # Duplicate public and protected member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5445 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5446 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5447 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5448 var _val = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5449 public var val = 10
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5450 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5451 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5452 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5453
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5454 # Duplicate class member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5455 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5456 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5457 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5458 static var s: string = "abc"
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5459 static var _s: string = "def"
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5460 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5461 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5462 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _s', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5463
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5464 # Duplicate public and protected class member variable
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5465 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5466 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5467 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5468 public static var s: string = "abc"
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5469 static var _s: string = "def"
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5470 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5471 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5472 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _s', 4)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5473
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5474 # Duplicate class and object member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5475 lines =<< trim END
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5476 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5477 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5478 static var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5479 var val = 20
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5480 def new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5481 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5482 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5483 var c = C.new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5484 assert_equal(10, C.val)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5485 assert_equal(20, c.val)
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5486 END
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
5487 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 4)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5488
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5489 # Duplicate object member variable in a derived class
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5490 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5491 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5492 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5493 var val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5494 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5495 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5496 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5497 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5498 var val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5499 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5500 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5501 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5502
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5503 # Duplicate object protected member variable in a derived class
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5504 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5505 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5506 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5507 var _val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5508 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5509 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5510 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5511 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5512 var _val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5513 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5514 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5515 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5516
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5517 # Duplicate object protected member variable in a derived class
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5518 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5519 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5520 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5521 var val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5522 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5523 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5524 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5525 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5526 var _val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5527 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5528 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5529 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: _val', 9)
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5530
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5531 # Duplicate object member variable in a derived class
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5532 lines =<< trim END
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5533 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5534 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5535 var _val = 10
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5536 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5537 class B extends A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5538 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5539 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5540 var val = 20
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5541 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5542 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5543 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: val', 9)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5544
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5545 # Two member variables with a common prefix
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5546 lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5547 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5548 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5549 public static var svar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5550 public static var svar: number
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5551 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5552 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5553 v9.CheckSourceSuccess(lines)
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5554 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5555
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5556 " Test for accessing a protected member outside a class in a def function
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5557 def Test_private_member_access_outside_class()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5558 # protected object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5559 var lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5560 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5561 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5562 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5563 def GetVal(): number
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5564 return this._val
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5565 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5566 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5567 def T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5568 var a = A.new()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5569 a._val = 20
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5570 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5571 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5572 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5573 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5574
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5575 # access a non-existing protected object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5576 lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5577 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5578 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5579 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5580 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5581 def T()
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5582 var a = A.new()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5583 a._a = 1
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5584 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5585 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5586 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5587 v9.CheckSourceFailure(lines, 'E1326: Variable "_a" not found in object "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5588
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5589 # protected static member variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5590 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5591 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5592 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5593 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5594 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5595 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5596 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5597 var x = a._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5598 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5599 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5600 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5601 v9.CheckSourceFailure(lines, 'E1375: Class variable "_val" accessible only using class "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5602
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5603 # protected static member variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5604 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5605 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5606 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5607 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5608 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5609 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5610 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5611 a._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5612 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5613 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5614 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5615 v9.CheckSourceFailure(lines, 'E1375: Class variable "_val" accessible only using class "A"', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5616
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5617 # protected static class variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5618 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5619 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5620 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5621 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5622 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5623 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5624 var x = A._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5625 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5626 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5627 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5628 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5629
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5630 # protected static class variable
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5631 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5632 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5633 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5634 static var _val = 10
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5635 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5636 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5637 A._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5638 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5639 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5640 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5641 v9.CheckSourceFailure(lines, 'E1333: Cannot access protected variable "_val" in class "A"', 1)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5642 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5643
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5644 " Test for changing the member access of an interface in a implementation class
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5645 def Test_change_interface_member_access()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5646 var lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5647 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5648 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5649 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5650 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5651 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5652 public var val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5653 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5654 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5655 v9.CheckSourceFailure(lines, 'E1367: Access level of variable "val" of interface "A" is different', 7)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5656
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5657 lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5658 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5659 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5660 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5661 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5662 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5663 public var val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5664 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5665 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5666 v9.CheckSourceFailure(lines, 'E1367: Access level of variable "val" of interface "A" is different', 7)
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5667 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5668
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5669 " Test for trying to change a readonly member from a def function
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5670 def Test_readonly_member_change_in_def_func()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5671 var lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5672 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5673 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5674 var val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5675 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5676 def T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5677 var a = A.new()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5678 a.val = 20
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5679 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5680 T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5681 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5682 v9.CheckSourceFailure(lines, 'E1335: Variable "val" in class "A" is not writable', 2)
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5683 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5684
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5685 " Test for reading and writing a class member from a def function
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5686 def Test_modify_class_member_from_def_function()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5687 var lines =<< trim END
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5688 vim9script
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5689 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5690 var var1: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5691 public static var var2: list<number> = [1, 2]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5692 public static var var3: dict<number> = {a: 1, b: 2}
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5693 static var _priv_var4: number = 40
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5694 endclass
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5695 def T()
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5696 assert_equal([1, 2], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5697 assert_equal({a: 1, b: 2}, A.var3)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5698 A.var2 = [3, 4]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5699 A.var3 = {c: 3, d: 4}
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5700 assert_equal([3, 4], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5701 assert_equal({c: 3, d: 4}, A.var3)
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5702 assert_fails('echo A._priv_var4', 'E1333: Cannot access protected variable "_priv_var4" in class "A"')
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5703 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5704 T()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5705 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5706 v9.CheckSourceSuccess(lines)
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5707 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5708
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5709 " Test for accessing a class member variable using an object
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5710 def Test_class_variable_access_using_object()
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5711 var lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5712 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5713 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5714 public static var svar1: list<number> = [1]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5715 public static var svar2: list<number> = [2]
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5716 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5717
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5718 A.svar1->add(3)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5719 A.svar2->add(4)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5720 assert_equal([1, 3], A.svar1)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5721 assert_equal([2, 4], A.svar2)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5722
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5723 def Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5724 A.svar1->add(7)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5725 A.svar2->add(8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5726 assert_equal([1, 3, 7], A.svar1)
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5727 assert_equal([2, 4, 8], A.svar2)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5728 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5729 Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5730 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5731 v9.CheckSourceSuccess(lines)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5732
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5733 # Cannot read from a class variable using an object in script context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5734 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5735 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5736 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5737 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5738 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5739 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5740
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5741 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5742 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5743 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
5744 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5745
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5746 # Cannot write to a class variable using an object in script context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5747 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5748 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5749 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5750 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5751 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5752 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5753
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5754 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5755 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5756 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5757 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 8)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5758
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5759 # Cannot read from a class variable using an object in def method context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5760 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5761 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5762 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5763 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5764 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5765 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5766
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5767 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5768 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5769 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5770 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5771 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5772 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5773 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 2)
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5774
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5775 # Cannot write to a class variable using an object in def method context
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5776 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5777 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5778 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5779 public var var1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5780 public static var svar2: list<number> = [1]
33225
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5781 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5782
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5783 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5784 var a = A.new()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5785 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5786 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5787 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5788 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5789 v9.CheckSourceFailure(lines, 'E1375: Class variable "svar2" accessible only using class "A"', 2)
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5790 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5791
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5792 " Test for using a interface method using a child object
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5793 def Test_interface_method_from_child()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5794 var lines =<< trim END
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5795 vim9script
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5796
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5797 interface A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5798 def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5799 endinterface
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5800
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5801 class B implements A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5802 def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5803 return 'foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5804 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5805 endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5806
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5807 class C extends B
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5808 def Bar(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5809 return 'bar'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5810 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5811 endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5812
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5813 def T1(a: A)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5814 assert_equal('foo', a.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5815 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5816
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5817 def T2(b: B)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5818 assert_equal('foo', b.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5819 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5820
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5821 var c = C.new()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5822 T1(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5823 T2(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5824 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5825 v9.CheckSourceSuccess(lines)
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5826 enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5827
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5828 " Test for using an interface method using a child object when it is overridden
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5829 " by the child class.
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5830 " FIXME: This test fails.
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5831 " def Test_interface_overridden_method_from_child()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5832 " var lines =<< trim END
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5833 " vim9script
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5834 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5835 " interface A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5836 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5837 " endinterface
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5838 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5839 " class B implements A
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5840 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5841 " return 'b-foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5842 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5843 " endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5844 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5845 " class C extends B
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5846 " def Bar(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5847 " return 'bar'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5848 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5849 " def Foo(): string
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5850 " return 'c-foo'
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5851 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5852 " endclass
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5853 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5854 " def T1(a: A)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5855 " assert_equal('c-foo', a.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5856 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5857 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5858 " def T2(b: B)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5859 " assert_equal('c-foo', b.Foo())
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5860 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5861 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5862 " var c = C.new()
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5863 " T1(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5864 " T2(c)
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5865 " END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5866 " v9.CheckSourceSuccess(lines)
33211
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5867 " enddef
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5868
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5869 " Test for abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5870 def Test_abstract_method()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5871 # Use two abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5872 var lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5873 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5874 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5875 def M1(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5876 return 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5877 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5878 abstract def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5879 abstract def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5880 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5881 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5882 def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5883 return 20
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5884 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5885 def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5886 return 30
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5887 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5888 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5889 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5890 assert_equal([10, 20, 30], [b.M1(), b.M2(), b.M3()])
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5891 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5892 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5893
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5894 # Don't define an abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5895 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5896 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5897 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5898 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5899 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5900 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5901 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5902 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5903 v9.CheckSourceFailure(lines, 'E1373: Abstract method "Foo" is not implemented', 6)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5904
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5905 # Use abstract method in a concrete class
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5906 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5907 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5908 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5909 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5910 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5911 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5912 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5913 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5914 v9.CheckSourceFailure(lines, 'E1372: Abstract method "abstract def Foo()" cannot be defined in a concrete class', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5915
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5916 # Use abstract method in an interface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5917 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5918 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5919 interface A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5920 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5921 endinterface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5922 class B implements A
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5923 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5924 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5925 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5926 END
33700
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5927 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5928
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5929 # Use abstract static method in an interface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5930 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5931 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5932 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5933 abstract static def Foo()
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5934 enddef
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5935 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5936 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5937 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5938
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5939 # Use abstract static variable in an interface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5940 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5941 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5942 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5943 abstract static foo: number = 10
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5944 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5945 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5946 v9.CheckSourceFailure(lines, 'E1404: Abstract cannot be used in an interface', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5947
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5948 # Abbreviate the "abstract" keyword
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5949 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5950 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5951 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5952 abs def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5953 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5954 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5955 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: abs def Foo()', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5956
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5957 # Use "abstract" with a member variable
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5958 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5959 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5960 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5961 abstract this.val = 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5962 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5963 END
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5964 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5965
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5966 # Use a static abstract method
33708
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5967 lines =<< trim END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5968 vim9script
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5969 abstract class A
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5970 abstract static def Foo(): number
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5971 endclass
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5972 END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5973 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5974
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5975 # Type mismatch between abstract method and concrete method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5976 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5977 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5978 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5979 abstract def Foo(a: string, b: number): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5980 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5981 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5982 def Foo(a: number, b: string): list<string>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5983 return []
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5984 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5985 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5986 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5987 v9.CheckSourceFailure(lines, 'E1383: Method "Foo": type mismatch, expected func(string, number): list<number> but got func(number, string): list<string>', 9)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5988
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5989 # Invoke an abstract method from a def function
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5990 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5991 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5992 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5993 abstract def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5994 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5995 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5996 def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5997 return [3, 5]
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5998 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5999 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6000 def Bar(c: B)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6001 assert_equal([3, 5], c.Foo())
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6002 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6003 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6004 Bar(b)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6005 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6006 v9.CheckSourceSuccess(lines)
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6007
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6008 # Use a static method in an abstract class
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6009 lines =<< trim END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6010 vim9script
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6011 abstract class A
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6012 static def Foo(): string
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6013 return 'foo'
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6014 enddef
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6015 endclass
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6016 assert_equal('foo', A.Foo())
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6017 END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
6018 v9.CheckSourceSuccess(lines)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6019 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6020
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6021 " Test for calling a class method from a subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6022 def Test_class_method_call_from_subclass()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6023 # class method call from a subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6024 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6025 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6026
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6027 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6028 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6029 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6030 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6031 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6032
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6033 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6034 def Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6035 Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6036 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6037 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6038
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6039 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6040 b.Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6041 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6042 v9.CheckSourceFailure(lines, 'E1384: Class method "Foo" accessible only inside class "A"', 1)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6043 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
6044
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6045 " Test for calling a class method using an object in a def function context and
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6046 " script context.
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6047 def Test_class_method_call_using_object()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6048 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6049 var lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6050 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6051 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6052 static def Foo(): list<string>
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6053 return ['a', 'b']
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6054 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6055 def Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6056 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6057 assert_equal(['a', 'b'], Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6058 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6059 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6060
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6061 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6062 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6063 var t_a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6064 t_a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6065 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6066
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6067 assert_equal(['a', 'b'], A.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6068 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6069 a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6070 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6071 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6072 v9.CheckSourceSuccess(lines)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6073
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6074 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6075 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6076 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6077 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6078 static def Foo(): string
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6079 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6080 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6081 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6082
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6083 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6084 assert_equal('foo', a.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6085 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6086 v9.CheckSourceFailure(lines, 'E1385: Class method "Foo" accessible only using class "A"', 9)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6087
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6088 # def function context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6089 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6090 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6091 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6092 static def Foo(): string
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6093 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6094 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6095 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6096
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6097 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6098 var a = A.new()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6099 assert_equal('foo', a.Foo())
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6100 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6101 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6102 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6103 v9.CheckSourceFailure(lines, 'E1385: Class method "Foo" accessible only using class "A"', 2)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6104 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6105
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6106 def Test_class_variable()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6107 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6108 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6109
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6110 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6111 public static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6112 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6113 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6114 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6115 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6116 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6117 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6118 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6119
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6120 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6121 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6122
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6123 assert_equal(10, A.val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6124 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6125 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6126 a.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6127 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6128 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6129
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6130 def T1(a1: A)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6131 a1.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6132 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6133 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6134 T1(b)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6135
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6136 A.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6137 assert_equal(20, A.val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6138 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6139 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6140
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6141 # Modifying a parent class variable from a child class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6142 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6143 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6144
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6145 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6146 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6147 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6148
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6149 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6150 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6151 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6152 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6153 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6154 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6155 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6156 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6157
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6158 # Reading a parent class variable from a child class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6159 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6160 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6161
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6162 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6163 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6164 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6165
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6166 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6167 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6168 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6169 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6170 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6171 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6172 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6173 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6174
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6175 # Modifying a parent class variable from a child object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6176 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6177 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6178
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6179 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6180 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6181 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6182
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6183 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6184 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6185 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6186 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6187 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6188 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6189 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6190 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6191 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6192
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6193 # Reading a parent class variable from a child object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6194 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6195 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6196
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6197 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6198 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6199 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6200
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6201 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6202 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6203 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6204 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6205 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6206 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6207 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6208 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6209 v9.CheckSourceFailure(lines, 'E1374: Class variable "val" accessible only inside class "A"', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6210
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6211 # Modifying a class variable using an object at script level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6212 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6213 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6214
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6215 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6216 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6217 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6218 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6219 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6220 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6221 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6222
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6223 # Reading a class variable using an object at script level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6224 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6225 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6226
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6227 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6228 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6229 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6230 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6231 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6232 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
6233 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6234
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6235 # Modifying a class variable using an object at function level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6236 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6237 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6238
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6239 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6240 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6241 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6242
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6243 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6244 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6245 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6246 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6247 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6248 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6249 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 2)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6250
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6251 # Reading a class variable using an object at function level
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6252 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6253 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6254
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6255 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6256 static var val: number = 10
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6257 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6258 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6259 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6260 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6261 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6262 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6263 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6264 v9.CheckSourceFailure(lines, 'E1375: Class variable "val" accessible only using class "A"', 2)
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6265
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6266 # Use old implicit var declaration syntax (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6267 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6268 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6269
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6270 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6271 static val: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6272 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6273 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6274 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6275
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6276 # Use old implicit var declaration syntax (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6277 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6278 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6279
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6280 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6281 static val: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6282 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6283 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6284 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6285
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6286 # Use old implicit var declaration syntax (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6287 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6288 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6289
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6290 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6291 static val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6292 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6293 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6294 v9.CheckSourceFailure(lines, 'E1368: Static must be followed by "var" or "def"', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6295
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6296 # Missing ":var" in "var" class variable declaration (without initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6297 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6298 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6299
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6300 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6301 static var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6302 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6303 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6304 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var: number', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6305
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6306 # Missing ":var" in "var" class variable declaration (with initialization)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6307 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6308 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6309
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6310 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6311 static var: number = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6312 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6313 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6314 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var: number = 10', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6315
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6316 # Missing ":var" in "var" class variable declaration (type inferred)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6317 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6318 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6319
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6320 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6321 static var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6322 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6323 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6324 v9.CheckSourceFailure(lines, 'E1329: Invalid class variable declaration: static var = 10', 4)
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6325
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6326 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6327
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6328 " Test for using a duplicate class method and class variable in a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6329 def Test_dup_class_member()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6330 # duplicate class variable, class method and overridden object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6331 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6332 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6333 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6334 static var sval = 100
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6335 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6336 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6337 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6338 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6339 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6340 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6341 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6342
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6343 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6344 static var sval = 200
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6345 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6346 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6347 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6348 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6349 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6350 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6351 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6352
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6353 def T1(aa: A): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6354 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6355 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6356
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6357 def T2(bb: B): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6358 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6359 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6360
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6361 assert_equal(100, A.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6362 assert_equal(200, B.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6363 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6364 assert_equal(100, a.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6365 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6366 assert_equal(200, b.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6367 assert_equal(200, T1(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6368 assert_equal(200, T2(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6369 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6370 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6371
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6372 # duplicate class variable and class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6373 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6374 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6375 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6376 static var sval = 100
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6377 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6378 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6379 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6380 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6381 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6382 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6383 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6384
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6385 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6386 static var sval = 200
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6387 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6388 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6389 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6390 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6391
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6392 def T1(aa: A): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6393 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6394 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6395
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6396 def T2(bb: B): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6397 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6398 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6399
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6400 assert_equal(100, A.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6401 assert_equal(200, B.sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6402 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6403 assert_equal(100, a.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6404 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6405 assert_equal(100, b.GetVal())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6406 assert_equal(100, T1(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6407 assert_equal(100, T2(b))
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6408 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6409 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6410 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6411
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6412 " Test for calling an instance method using the class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6413 def Test_instance_method_call_using_class()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6414 # Invoke an object method using a class in script context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6415 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6416 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6417 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6418 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6419 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6420 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6421 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6422 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6423 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6424 v9.CheckSourceFailure(lines, 'E1386: Object method "Foo" accessible only using class "A" object', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6425
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6426 # Invoke an object method using a class in def function context
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6427 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6428 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6429 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6430 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6431 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6432 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6433 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6434 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6435 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6436 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6437 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6438 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6439 v9.CheckSourceFailure(lines, 'E1386: Object method "Foo" accessible only using class "A" object', 1)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6440 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6441
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6442 " Test for duplicate class method and instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6443 def Test_dup_classmethod_objmethod()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6444 # Duplicate instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6445 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6446 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6447 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6448 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6449 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6450 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6451 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6452 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6453 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6454 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6455
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6456 # Duplicate protected instance method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6457 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6458 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6459 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6460 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6461 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6462 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6463 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6464 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6465 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6466 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6467
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6468 # Duplicate class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6469 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6470 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6471 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6472 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6473 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6474 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6475 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6476 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6477 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6478 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6479
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6480 # Duplicate protected class method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6481 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6482 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6483 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6484 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6485 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6486 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6487 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6488 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6489 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6490 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6491
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6492 # Duplicate protected class and object method
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6493 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6494 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6495 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6496 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6497 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6498 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6499 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6500 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6501 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6502 v9.CheckSourceFailure(lines, 'E1355: Duplicate function: _Foo', 6)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6503 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6504
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6505 " Test for an instance method access level comparison with parent instance
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6506 " methods.
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6507 def Test_instance_method_access_level()
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6508 # protected method in subclass
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6509 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6510 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6511 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6512 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6513 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6514 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6515 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6516 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6517 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6518 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6519 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6520 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6521 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6522 v9.CheckSourceFailure(lines, 'E1377: Access level of method "_Foo" is different in class "A"', 11)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6523
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6524 # Public method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6525 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6526 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6527 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6528 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6529 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6530 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6531 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6532 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6533 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6534 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6535 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6536 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6537 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6538 v9.CheckSourceFailure(lines, 'E1377: Access level of method "Foo" is different in class "A"', 11)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6539 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6540
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6541 def Test_extend_empty_class()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6542 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6543 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6544 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6545 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6546 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6547 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6548 class C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6549 public static var rw_class_var = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6550 public var rw_obj_var = 2
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6551 static def ClassMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6552 return 3
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6553 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6554 def ObjMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6555 return 4
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6556 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6557 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6558 assert_equal(1, C.rw_class_var)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6559 assert_equal(3, C.ClassMethod())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6560 var c = C.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6561 assert_equal(2, c.rw_obj_var)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6562 assert_equal(4, c.ObjMethod())
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6563 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6564 v9.CheckSourceSuccess(lines)
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6565 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6566
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6567 " A interface cannot have a static variable or a static method or a private
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6568 " variable or a protected method or a public variable
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6569 def Test_interface_with_unsupported_members()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6570 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6571 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6572 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6573 static var num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6574 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6575 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6576 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6577
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6578 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6579 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6580 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6581 static var _num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6582 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6583 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6584 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6585
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6586 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6587 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6588 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6589 public static var num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6590 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6591 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
6592 v9.CheckSourceFailure(lines, 'E1387: public variable not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6593
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6594 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6595 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6596 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6597 public static var num: number
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6598 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6599 END
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
6600 v9.CheckSourceFailure(lines, 'E1387: public variable not supported in an interface', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6601
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6602 lines =<< trim END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6603 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6604 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6605 static var _num: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6606 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6607 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6608 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6609
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6610 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6611 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6612 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6613 static def Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6614 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6615 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6616 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6617
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6618 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6619 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6620 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6621 static def _Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6622 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6623 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6624 v9.CheckSourceFailure(lines, 'E1378: Static member not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6625
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6626 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6627 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6628 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6629 var _Foo: list<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6630 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6631 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6632 v9.CheckSourceFailure(lines, 'E1379: Protected variable not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6633
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6634 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6635 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6636 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6637 def _Foo(d: dict<any>): list<string>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6638 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6639 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6640 v9.CheckSourceFailure(lines, 'E1380: Protected method not supported in an interface', 3)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6641 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6642
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6643 " Test for extending an interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6644 def Test_extend_interface()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6645 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6646 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6647 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6648 var var1: list<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6649 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6650 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6651 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6652 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6653 def Bar()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6654 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6655 class C implements A, B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6656 var var1 = [1, 2]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6657 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6658 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6659 var var2 = {a: '1'}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6660 def Bar()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6661 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6662 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6663 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6664 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6665
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6666 # extending empty interface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6667 lines =<< trim END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6668 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6669 interface A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6670 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6671 interface B extends A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6672 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6673 class C implements B
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6674 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6675 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6676 v9.CheckSourceSuccess(lines)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6677
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6678 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6679 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6680 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6681 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6682 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6683 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6684 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6685 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6686 class C implements A, B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6687 var var2 = {a: '1'}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6688 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6689 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6690 v9.CheckSourceFailure(lines, 'E1349: Method "Foo" of interface "A" is not implemented', 10)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6691
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6692 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6693 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6694 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6695 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6696 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6697 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6698 var var2: dict<string>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6699 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6700 class C implements A, B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6701 def Foo()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6702 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6703 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6704 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6705 v9.CheckSourceFailure(lines, 'E1348: Variable "var2" of interface "B" is not implemented', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6706
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6707 # interface cannot extend a class
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6708 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6709 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6710 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6711 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6712 interface B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6713 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6714 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6715 v9.CheckSourceFailure(lines, 'E1354: Cannot extend A', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6716
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6717 # class cannot extend an interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6718 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6719 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6720 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6721 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6722 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6723 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6724 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6725 v9.CheckSourceFailure(lines, 'E1354: Cannot extend A', 5)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6726
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6727 # interface cannot implement another interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6728 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6729 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6730 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6731 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6732 interface B implements A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6733 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6734 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6735 v9.CheckSourceFailure(lines, 'E1381: Interface cannot use "implements"', 4)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6736
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6737 # interface cannot extend multiple interfaces
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6738 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6739 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6740 interface A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6741 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6742 interface B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6743 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6744 interface C extends A, B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6745 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6746 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6747 v9.CheckSourceFailure(lines, 'E1315: White space required after name: A, B', 6)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6748
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6749 # Variable type in an extended interface is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6750 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6751 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6752 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6753 var val1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6754 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6755 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6756 var val2: string
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6757 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6758 interface C extends B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6759 var val1: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6760 var val2: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6761 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6762 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6763 v9.CheckSourceFailure(lines, 'E1382: Variable "val1": type mismatch, expected number but got string', 11)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6764 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6765
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6766 " Test for a child class implementing an interface when some of the methods are
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6767 " defined in the parent class.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6768 def Test_child_class_implements_interface()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6769 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6770 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6771
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6772 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6773 def F1(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6774 def F2(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6775 def F3(): list<list<number>>
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6776 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6777 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6778 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6779 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6780
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6781 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6782 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6783 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6784 def F3(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6785 return [[3]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6786 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6787 var v1: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6788 var var3 = [{c: 30}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6789 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6790
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6791 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6792 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6793 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6794 def F2(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6795 return [[2]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6796 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6797 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6798 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6799 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6800
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6801 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6802 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6803 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6804 def F1(): list<list<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6805 return [[1]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6806 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6807 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6808 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6809 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6810
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6811 def T(if: Intf)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6812 assert_equal([[1]], if.F1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6813 assert_equal([[2]], if.F2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6814 assert_equal([[3]], if.F3())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6815 assert_equal([{a: 10}], if.var1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6816 assert_equal([{b: 20}], if.var2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6817 assert_equal([{c: 30}], if.var3)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6818 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6819
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6820 var c = C.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6821 T(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6822 assert_equal([[1]], c.F1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6823 assert_equal([[2]], c.F2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6824 assert_equal([[3]], c.F3())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6825 assert_equal([{a: 10}], c.var1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6826 assert_equal([{b: 20}], c.var2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6827 assert_equal([{c: 30}], c.var3)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6828 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6829 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6830
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6831 # One of the interface methods is not found
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6832 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6833 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6834
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6835 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6836 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6837 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6838 def F3()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6839 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6840
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6841 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6842 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6843 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6844 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6845
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6846 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6847 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6848 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6849 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6850 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6851 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6852
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6853 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6854 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6855 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6856 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6857 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6858 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6859 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6860 v9.CheckSourceFailure(lines, 'E1349: Method "F3" of interface "Intf" is not implemented', 26)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6861
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6862 # One of the interface methods is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6863 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6864 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6865
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6866 interface Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6867 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6868 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6869 def F3()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6870 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6871
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6872 class A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6873 def F3(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6874 return 0
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6875 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6876 def A1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6877 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6878 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6879
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6880 class B extends A
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6881 def B1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6882 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6883 def F2()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6884 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6885 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6886
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6887 class C extends B implements Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6888 def C1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6889 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6890 def F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6891 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6892 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6893 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6894 v9.CheckSourceFailure(lines, 'E1383: Method "F3": type mismatch, expected func() but got func(): number', 29)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6895
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6896 # One of the interface variables is not present
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6897 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6898 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6899
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6900 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6901 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6902 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6903 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6904 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6905
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6906 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6907 var v1: list<list<number>> = [[0]]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6908 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6909
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6910 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6911 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6912 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6913 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6914
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6915 class C extends B implements Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6916 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6917 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6918 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6919 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6920 v9.CheckSourceFailure(lines, 'E1348: Variable "var3" of interface "Intf" is not implemented', 21)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6921
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6922 # One of the interface variables is of different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6923 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6924 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6925
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6926 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6927 var var1: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6928 var var2: list<dict<number>>
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6929 var var3: list<dict<number>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6930 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6931
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6932 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6933 var v1: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6934 var var3: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6935 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6936
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6937 class B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6938 var v2: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6939 var var2 = [{b: 20}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6940 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6941
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6942 class C extends B implements Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6943 var v3: list<list<number>> = [[0]]
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6944 var var1 = [{a: 10}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6945 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6946 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6947 v9.CheckSourceFailure(lines, 'E1382: Variable "var3": type mismatch, expected list<dict<number>> but got list<dict<string>>', 22)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6948 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6949
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6950 " Test for extending an interface with duplicate variables and methods
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6951 def Test_interface_extends_with_dup_members()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6952 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6953 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6954 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6955 var n1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6956 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6957 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6958 interface B extends A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6959 var n2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6960 var n1: number
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6961 def Foo2(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6962 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6963 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6964 class C implements B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6965 var n1 = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6966 var n2 = 20
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6967 def Foo1(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6968 return 30
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6969 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6970 def Foo2(): number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6971 return 40
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6972 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6973 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6974 def T1(a: A)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6975 assert_equal(10, a.n1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6976 assert_equal(30, a.Foo1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6977 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6978 def T2(b: B)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6979 assert_equal(10, b.n1)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6980 assert_equal(20, b.n2)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6981 assert_equal(30, b.Foo1())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6982 assert_equal(40, b.Foo2())
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6983 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6984 var c = C.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6985 T1(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6986 T2(c)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6987 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6988 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6989 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6990
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6991 " Test for using "any" type for a variable in a sub-class while it has a
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6992 " concrete type in the interface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6993 def Test_implements_using_var_type_any()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6994 var lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6995 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6996 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6997 var val: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6998 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6999 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7000 var val = [{a: '1'}, {b: '2'}]
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7001 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7002 var b = B.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7003 assert_equal([{a: '1'}, {b: '2'}], b.val)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7004 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7005 v9.CheckSourceSuccess(lines)
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7006
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7007 # initialize instance variable using a different type
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7008 lines =<< trim END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7009 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7010 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7011 var val: list<dict<string>>
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7012 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7013 class B implements A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7014 var val = {a: 1, b: 2}
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7015 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7016 var b = B.new()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7017 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7018 v9.CheckSourceFailure(lines, 'E1382: Variable "val": type mismatch, expected list<dict<string>> but got dict<number>', 1)
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7019 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
7020
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7021 " Test for assigning to a member variable in a nested class
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7022 def Test_nested_object_assignment()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7023 var lines =<< trim END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7024 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7025
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7026 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7027 var value: number
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7028 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7029
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7030 class B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7031 var a: A = A.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7032 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7033
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7034 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7035 var b: B = B.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7036 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7037
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7038 class D
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7039 var c: C = C.new()
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7040 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7041
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7042 def T(da: D)
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7043 da.c.b.a.value = 10
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7044 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7045
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7046 var d = D.new()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7047 T(d)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7048 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
7049 v9.CheckSourceFailure(lines, 'E1335: Variable "value" in class "A" is not writable', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7050 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
7051
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7052 " Test for calling methods using a null object
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7053 def Test_null_object_method_call()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7054 # Calling a object method using a null object in script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7055 var lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7056 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7057
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7058 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7059 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7060 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7061 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7062 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7063
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7064 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7065 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7066 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7067 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 10)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7068
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7069 # Calling a object method using a null object in def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7070 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7071 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7072
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7073 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7074 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7075 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7076 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7077 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7078
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7079 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7080 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7081 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7082 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7083 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7084 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7085 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7086
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7087 # Calling a object method through another class method using a null object in
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7088 # script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7089 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7090 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7091
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7092 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7093 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7094 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7095 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7096
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7097 static def Bar(o_any: any)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7098 var o_typed: C = o_any
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7099 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7100 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7101 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7102
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7103 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7104 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7105 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7106 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7107
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7108 # Calling a object method through another class method using a null object in
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7109 # def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7110 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7111 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7112
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7113 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7114 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7115 assert_report('This method should not be executed')
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7116 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7117
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7118 static def Bar(o_any: any)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7119 var o_typed: C = o_any
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7120 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7121 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7122 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7123
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7124 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7125 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7126 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7127 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7128 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7129 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7130 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 2)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7131 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7132
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7133 " Test for using a dict as an object member
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7134 def Test_dict_object_member()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7135 var lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7136 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7137
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7138 class Context
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7139 public var state: dict<number> = {}
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7140 def GetState(): dict<number>
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7141 return this.state
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7142 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7143 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7144
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7145 var ctx = Context.new()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7146 ctx.state->extend({a: 1})
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7147 ctx.state['b'] = 2
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7148 assert_equal({a: 1, b: 2}, ctx.GetState())
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7149
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7150 def F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7151 ctx.state['c'] = 3
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7152 assert_equal({a: 1, b: 2, c: 3}, ctx.GetState())
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7153 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7154 F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7155 assert_equal(3, ctx.state.c)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7156 ctx.state.c = 4
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7157 assert_equal(4, ctx.state.c)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7158 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7159 v9.CheckSourceSuccess(lines)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7160 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7161
33337
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7162 " The following test was failing after 9.0.1914. This was caused by using a
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7163 " freed object from a previous method call.
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7164 def Test_freed_object_from_previous_method_call()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7165 var lines =<< trim END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7166 vim9script
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7167
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7168 class Context
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7169 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7170
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7171 class Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7172 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7173
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7174 def Failure(): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7175 return Result.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7176 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7177
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7178 def GetResult(ctx: Context): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7179 return Failure()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7180 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7181
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7182 def Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7183 var ctx = Context.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7184 var result = GetResult(ctx)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7185 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7186
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7187 Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7188 END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7189 v9.CheckSourceSuccess(lines)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7190 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7191
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7192 " Test for duplicate object and class variable
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7193 def Test_duplicate_variable()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7194 # Object variable name is same as the class variable name
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7195 var lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7196 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7197 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7198 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7199 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7200 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7201 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7202 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7203 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7204
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7205 # Duplicate variable name and calling a class method
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7206 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7207 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7208 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7209 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7210 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7211 def F1()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7212 echo this.sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7213 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7214 static def F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7215 echo sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7216 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7217 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7218 A.F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7219 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7220 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7221
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7222 # Duplicate variable with an empty constructor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7223 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7224 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7225 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7226 public static var sval: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7227 public var sval: number
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7228 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7229 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7230 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7231 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7232 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7233 v9.CheckSourceFailure(lines, 'E1369: Duplicate variable: sval', 4)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7234 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7235
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7236 " Test for using a reserved keyword as a variable name
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7237 def Test_reserved_varname()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7238 for kword in ['true', 'false', 'null', 'null_blob', 'null_dict',
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7239 'null_function', 'null_list', 'null_partial', 'null_string',
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7240 'null_channel', 'null_job', 'super', 'this']
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7241
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7242 var lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7243 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7244 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7245 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7246 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7247 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7248 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7249 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7250
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7251 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7252 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7253 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7254 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7255 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7256 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7257 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7258 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7259 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7260 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7261
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7262 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7263 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7264 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7265 public var {kword}: list<number> = [1, 2, 3]
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7266 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7267 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7268 def F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7269 echo this.{kword}
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7270 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7271 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7272 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7273 o.F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7274 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7275 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7276
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7277 # class variable name
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7278 if kword != 'this'
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7279 lines =<< trim eval END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7280 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7281 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7282 public static var {kword}: list<number> = [1, 2, 3]
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7283 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7284 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7285 v9.CheckSourceFailure(lines, $'E1034: Cannot use reserved name {kword}', 3)
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7286 endif
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7287 endfor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7288 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7289
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7290 " Test for checking the type of the arguments and the return value of a object
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7291 " method in an extended class.
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7292 def Test_extended_obj_method_type_check()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7293 var lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7294 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7295
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7296 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7297 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7298 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7299 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7300 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7301 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7302
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7303 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7304 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7305 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7306 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7307 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7308
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7309 class Bar extends Foo
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7310 def Doit(p: C): B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7311 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7312 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7313 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7314 END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7315 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<C>): object<B>', 20)
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7316
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7317 lines =<< trim END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7318 vim9script
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7319
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7320 class A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7321 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7322 class B extends A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7323 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7324 class C extends B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7325 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7326
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7327 class Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7328 def Doit(p: B): B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7329 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7330 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7331 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7332
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7333 class Bar extends Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7334 def Doit(p: B): C
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7335 return C.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7336 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7337 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7338 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7339 v9.CheckSourceSuccess(lines)
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7340
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7341 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7342 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7343
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7344 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7345 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7346 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7347 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7348 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7349 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7350
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7351 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7352 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7353 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7354 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7355 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7356
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7357 class Bar extends Foo
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7358 def Doit(p: A): B
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7359 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7360 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7361 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7362 END
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7363 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<A>): object<B>', 20)
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7364
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7365 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7366 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7367
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7368 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7369 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7370 class B extends A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7371 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7372 class C extends B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7373 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7374
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7375 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7376 def Doit(p: B): B
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7377 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7378 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7379 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7380
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7381 class Bar extends Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7382 def Doit(p: B): A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7383 return A.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7384 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7385 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7386 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7387 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<B>): object<A>', 20)
33598
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7388
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7389 # check varargs type mismatch
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7390 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7391 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7392
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7393 class B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7394 def F(...xxx: list<any>)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7395 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7396 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7397 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7398 def F(xxx: list<any>)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7399 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7400 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7401 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7402 v9.CheckSourceFailure(lines, 'E1383: Method "F": type mismatch, expected func(...list<any>) but got func(list<any>)', 10)
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7403 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7404
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7405 " Test type checking for class variable in assignments
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7406 func Test_class_variable_complex_type_check()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7407 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7408 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7409 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7410 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7411 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7412 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7413 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7414 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7415 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7416 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7417 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7418 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7419 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7420 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 9)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7421
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7422 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7423 " class def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7424 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7425 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7426 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7427 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7428 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7429 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7430 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7431 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7432 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7433 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7434 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7435 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7436 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7437 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7438 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7439 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7440
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7441 " class variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7442 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7443 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7444 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7445 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7446 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7447 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7448 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7449 public static var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7450 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7451 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7452 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7453 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7454 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7455 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7456 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7457 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7458
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7459 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7460 " expression type. Try assigning a different type from script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7461 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7462 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7463 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7464 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7465 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7466 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7467 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7468 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7469 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7470 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7471 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7472 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 9)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7473
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7474 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7475 " expression type. Try assigning a different type at class def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7476 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7477 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7478 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7479 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7480 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7481 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7482 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7483 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7484 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7485 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7486 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7487 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7488 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7489 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7490 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7491 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7492
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7493 " class variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7494 " expression type. Try assigning a different type at script def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7495 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7496 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7497 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7498 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7499 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7500 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7501 public static var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7502 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7503 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7504 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7505 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7506 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7507 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7508 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7509 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7510
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7511 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7512 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7513 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7514 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7515 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7516 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7517 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7518 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7519 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7520 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7521 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7522 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7523 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7524 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7525 assert_equal('string', typename(A.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7526 A.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7527 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7528 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7529 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7530 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7531 assert_equal('string', typename(A.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7532 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7533 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7534
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7535 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7536 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7537 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7538 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7539 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7540 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7541 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7542 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7543 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7544
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7545 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7546 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7547 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7548 assert_equal('string', typename(Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7549 Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7550 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7551 Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7552 assert_equal('string', typename(Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7553 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7554 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7555 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7556 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7557 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7558 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7559 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7560 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7561 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7562 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7563
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7564 " class variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7565 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7566 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7567 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7568 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7569 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7570 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7571 public static var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7572 public static var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7573 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7574
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7575 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7576 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7577 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7578 assert_equal('string', typename(A.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7579 A.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7580 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(A.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7581 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7582 assert_equal('string', typename(A.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7583 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7584 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7585 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7586 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7587 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7588 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7589 call v9.CheckSourceSuccess(lines)
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7590
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7591 let lines =<< trim END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7592 vim9script
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7593 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7594 public static var foo = [0z10, 0z20]
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7595 endclass
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7596 assert_equal([0z10, 0z20], A.foo)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7597 A.foo = [0z30]
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7598 assert_equal([0z30], A.foo)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7599 var a = A.foo
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7600 assert_equal([0z30], a)
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7601 END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7602 call v9.CheckSourceSuccess(lines)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7603 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7604
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7605 " Test type checking for object variable in assignments
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7606 func Test_object_variable_complex_type_check()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7607 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7608 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7609 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7610 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7611 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7612 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7613 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7614 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7615 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7616 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7617 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7618 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7619 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7620 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7621 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 10)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7622
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7623 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7624 " object def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7625 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7626 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7627 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7628 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7629 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7630 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7631 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7632 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7633 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7634 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7635 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7636 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7637 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7638 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7639 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7640 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7641 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7642
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7643 " object variable with a specific type. Try assigning a different type at
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7644 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7645 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7646 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7647 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7648 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7649 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7650 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7651 public var Fn: func(list<dict<blob>>): dict<list<blob>> = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7652 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7653 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7654 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7655 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7656 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7657 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7658 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7659 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7660 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7661 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 2)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7662
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7663 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7664 " expression type. Try assigning a different type from script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7665 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7666 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7667 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7668 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7669 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7670 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7671 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7672 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7673 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7674 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7675 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7676 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7677 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 10)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7678
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7679 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7680 " expression type. Try assigning a different type at object def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7681 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7682 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7683 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7684 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7685 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7686 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7687 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7688 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7689 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7690 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7691 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7692 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7693 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7694 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7695 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7696 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7697 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 1)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7698
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7699 " object variable without any type. Should be set to the initialization
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7700 " expression type. Try assigning a different type at script def level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7701 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7702 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7703 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7704 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7705 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7706 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7707 public var Fn = Foo
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7708 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7709 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7710 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7711 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7712 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7713 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7714 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7715 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7716 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7717 call v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(list<dict<blob>>): dict<list<blob>> but got string', 2)
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7718
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7719 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7720 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7721 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7722 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7723 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7724 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7725 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7726 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7727 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7728 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7729
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7730 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7731 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7732 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7733 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7734 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7735 assert_equal('string', typename(a.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7736 a.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7737 test_garbagecollect_now()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7738 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7739 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7740 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7741 assert_equal('string', typename(a.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7742 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7743 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7744
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7745 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7746 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7747 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7748 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7749 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7750 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7751 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7752 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7753 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7754
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7755 def Bar()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7756 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(this.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7757 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7758 assert_equal('string', typename(this.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7759 this.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7760 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(this.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7761 this.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7762 assert_equal('string', typename(this.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7763 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7764 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7765
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7766 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7767 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7768 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7769 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7770 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7771 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7772 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7773 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7774
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7775 " object variable with 'any" type. Can be assigned different types.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7776 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7777 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7778 def Foo(l: list<dict<blob>>): dict<list<blob>>
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7779 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7780 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7781 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7782 public var Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7783 public var Fn2: any
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7784 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7785
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7786 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7787 var a = A.new()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7788 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7789 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7790 assert_equal('string', typename(a.Fn))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7791 a.Fn2 = Foo
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7792 assert_equal('func(list<dict<blob>>): dict<list<blob>>', typename(a.Fn2))
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7793 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7794 assert_equal('string', typename(a.Fn2))
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7795 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7796 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7797 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7798 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7799 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7800 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7801 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7802 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7803
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7804 " Test for recursively calling an object method. This used to cause an
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7805 " use-after-free error.
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7806 def Test_recursive_object_method_call()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7807 var lines =<< trim END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7808 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7809 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7810 var val: number = 0
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7811 def Foo(): number
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7812 if this.val >= 90
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7813 return this.val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7814 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7815 this.val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7816 return this.Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7817 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7818 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7819 var a = A.new()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7820 assert_equal(90, a.Foo())
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7821 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7822 v9.CheckSourceSuccess(lines)
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7823 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7824
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7825 " Test for recursively calling a class method.
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7826 def Test_recursive_class_method_call()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7827 var lines =<< trim END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7828 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7829 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7830 static var val: number = 0
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7831 static def Foo(): number
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7832 if val >= 90
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7833 return val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7834 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7835 val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7836 return Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7837 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7838 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7839 assert_equal(90, A.Foo())
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7840 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7841 v9.CheckSourceSuccess(lines)
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7842 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7843
33517
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7844 " Test for checking the argument types and the return type when assigning a
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7845 " funcref to make sure the invariant class type is used.
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7846 def Test_funcref_argtype_returntype_check()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7847 var lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7848 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7849 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7850 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7851 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7852 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7853
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7854 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7855 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7856 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7857
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7858 var Bar: func(A): A = Foo
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7859 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7860 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 11)
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7861
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7862 lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7863 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7864 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7865 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7866 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7867 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7868
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7869 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7870 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7871 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7872
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7873 def Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7874 var Bar: func(A): A = Foo
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7875 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7876 Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7877 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7878 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<A>): object<A> but got func(object<B>): object<B>', 1)
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7879 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7880
33598
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7881 def Test_funcref_argtype_invariance_check()
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7882 var lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7883 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7884
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7885 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7886 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7887 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7888 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7889 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7890 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7891
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7892 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7893 Func = (o: B): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7894 assert_equal(3, Func(B.new()))
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7895 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7896 v9.CheckSourceSuccess(lines)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7897
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7898 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7899 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7900
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7901 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7902 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7903 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7904 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7905 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7906 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7907
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7908 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7909 Func = (o: A): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7910 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7911 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<B>): number but got func(object<A>): number', 11)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7912
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7913 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7914 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7915
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7916 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7917 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7918 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7919 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7920 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7921 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7922
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7923 var Func: func(B): number
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7924 Func = (o: C): number => 3
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7925 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7926 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected func(object<B>): number but got func(object<C>): number', 11)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7927 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7928
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7929 " Test for using an operator (e.g. +) with an assignment
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7930 def Test_op_and_assignment()
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7931 # Using += with a class variable
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7932 var lines =<< trim END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7933 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7934 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7935 public static var val: list<number> = []
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7936 static def Foo(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7937 val += [1]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7938 return val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7939 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7940 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7941 def Bar(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7942 A.val += [2]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7943 return A.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7944 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7945 assert_equal([1], A.Foo())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7946 assert_equal([1, 2], Bar())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7947 A.val += [3]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7948 assert_equal([1, 2, 3], A.val)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7949 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7950 v9.CheckSourceSuccess(lines)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7951
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7952 # Using += with an object variable
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7953 lines =<< trim END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7954 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7955 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7956 public var val: list<number> = []
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7957 def Foo(): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7958 this.val += [1]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7959 return this.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7960 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7961 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7962 def Bar(bar_a: A): list<number>
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7963 bar_a.val += [2]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7964 return bar_a.val
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7965 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7966 var a = A.new()
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7967 assert_equal([1], a.Foo())
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7968 assert_equal([1, 2], Bar(a))
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7969 a.val += [3]
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7970 assert_equal([1, 2, 3], a.val)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7971 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7972 v9.CheckSourceSuccess(lines)
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7973 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7974
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7975 " Test for using an object method as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7976 def Test_object_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7977 # Using object method funcref from a def function
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7978 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7979 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7980 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7981 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7982 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7983 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7984 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7985 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7986 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7987 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7988 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7989 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7990 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7991 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7992 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7993
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7994 # Using object method funcref at the script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7995 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7996 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7997 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7998 def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7999 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8000 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8001 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8002 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8003 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8004 assert_equal({a: 1, b: 2}, Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8005 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8006 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8007
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8008 # Using object method funcref at the script level
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8009 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8010 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8011 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8012 var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8013 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8014 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8015 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8016 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8017 var a = A.new(345)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8018 var Fn = a.Foo
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8019 assert_equal(345, Fn())
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8020 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8021 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8022
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8023 # Using object method funcref from another object method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8024 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8025 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8026 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8027 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8028 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8029 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8030 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8031 var Fn = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8032 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8033 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8034 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8035 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8036 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8037 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8038 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8039
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8040 # Using function() to get a object method funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8041 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8042 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8043 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8044 def Foo(l: list<any>): list<any>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8045 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8046 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8047 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8048 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8049 var Fn = function(a.Foo, [[{a: 1, b: 2}, [3, 4]]])
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8050 assert_equal([{a: 1, b: 2}, [3, 4]], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8051 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8052 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8053
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8054 # Use an object method with a function returning a funcref and then call the
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8055 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8056 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8057 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8058
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8059 def Map(F: func(number): number): func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8060 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8061 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8062
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8063 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8064 def Double(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8065 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8066 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8067 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8068
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8069 const math = Math.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8070 assert_equal(48, Map(math.Double)(24))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8071 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8072 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8073
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8074 # Try using a protected object method funcref from a def function
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8075 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8076 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8077 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8078 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8079 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8080 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8081 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8082 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8083 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8084 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8085 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8086 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8087 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 2)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8088
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8089 # Try using a protected object method funcref at the script level
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8090 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8091 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8092 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8093 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8094 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8095 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8096 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8097 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8098 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8099 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 7)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8100
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8101 # Using a protected object method funcref from another object method
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8102 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8103 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8104 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8105 def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8106 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8107 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8108 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8109 var Fn = this._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8110 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8111 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8112 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8113 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8114 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8115 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8116 v9.CheckSourceSuccess(lines)
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8117
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8118 # Using object method funcref using call()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8119 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8120 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8121 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8122 var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8123 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8124 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8125 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8126 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8127
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8128 def Bar(obj: A)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8129 assert_equal(123, call(obj.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8130 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8131
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8132 var a = A.new(123)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8133 Bar(a)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8134 assert_equal(123, call(a.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8135 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8136 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8137 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8138
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8139 " Test for using a class method as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8140 def Test_class_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8141 # Using class method funcref in a def function
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8142 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8143 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8144 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8145 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8146 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8147 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8148 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8149 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8150 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8151 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8152 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8153 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8154 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8155 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8156
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8157 # Using class method funcref at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8158 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8159 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8160 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8161 static def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8162 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8163 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8164 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8165 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8166 assert_equal({a: 1, b: 2}, Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8167 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8168 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8169
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8170 # Using class method funcref at the script level
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8171 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8172 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8173 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8174 public static var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8175 static def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8176 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8177 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8178 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8179 A.val = 567
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8180 var Fn = A.Foo
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8181 assert_equal(567, Fn())
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8182 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8183 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8184
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8185 # Using function() to get a class method funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8186 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8187 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8188 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8189 static def Foo(l: list<any>): list<any>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8190 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8191 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8192 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8193 var Fn = function(A.Foo, [[{a: 1, b: 2}, [3, 4]]])
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8194 assert_equal([{a: 1, b: 2}, [3, 4]], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8195 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8196 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8197
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8198 # Using a class method funcref from another class method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8199 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8200 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8201 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8202 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8203 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8204 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8205 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8206 var Fn = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8207 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8208 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8209 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8210 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8211 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8212 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8213
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8214 # Use a class method with a function returning a funcref and then call the
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8215 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8216 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8217 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8218
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8219 def Map(F: func(number): number): func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8220 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8221 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8222
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8223 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8224 static def StaticDouble(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8225 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8226 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8227 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8228
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8229 assert_equal(48, Map(Math.StaticDouble)(24))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8230 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8231 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8232
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8233 # Try using a protected class method funcref in a def function
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8234 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8235 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8236 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8237 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8238 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8239 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8240 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8241 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8242 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8243 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8244 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8245 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 1)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8246
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8247 # Try using a protected class method funcref at script level
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8248 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8249 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8250 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8251 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8252 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8253 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8254 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8255 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8256 v9.CheckSourceFailure(lines, 'E1366: Cannot access protected method: _Foo', 6)
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8257
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8258 # Using a protected class method funcref from another class method
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8259 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8260 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8261 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8262 static def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8263 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8264 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8265 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8266 var Fn = _Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8267 assert_equal([3, 2, 1], Fn())
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8268 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8269 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8270 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8271 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8272 v9.CheckSourceSuccess(lines)
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8273
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8274 # Using class method funcref using call()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8275 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8276 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8277 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8278 public static var val: number
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8279 static def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8280 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8281 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8282 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8283
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8284 def Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8285 A.val = 468
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8286 assert_equal(468, call(A.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8287 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8288 Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8289 assert_equal(468, call(A.Foo, []))
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8290 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8291 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8292 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8293
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8294 " Test for using an object member as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8295 def Test_object_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8296 # Using a funcref object variable in an object method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8297 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8298 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8299 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8300 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8301 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8302
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8303 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8304 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8305 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8306 assert_equal(200, this.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8307 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8308 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8309
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8310 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8311 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8312 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8313 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8314
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8315 # Using a funcref object variable in a def method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8316 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8317 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8318 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8319 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8320 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8321
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8322 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8323 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8324 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8325
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8326 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8327 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8328 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8329 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8330 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8331 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8332 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8333
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8334 # Using a funcref object variable at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8335 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8336 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8337 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8338 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8339 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8340
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8341 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8342 var Cb: func(number): number = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8343 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8344
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8345 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8346 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8347 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8348 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8349
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8350 # Using a funcref object variable pointing to an object method in an object
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8351 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8352 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8353 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8354 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8355 var Cb: func(number): number = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8356 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8357 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8358 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8359 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8360 assert_equal(200, this.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8361 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8362 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8363
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8364 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8365 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8366 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8367 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8368
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8369 # Using a funcref object variable pointing to an object method in a def
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8370 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8371 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8372 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8373 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8374 var Cb: func(number): number = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8375 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8376 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8377 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8378 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8379
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8380 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8381 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8382 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8383 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8384 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8385 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8386 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8387
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8388 # Using a funcref object variable pointing to an object method at script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8389 # level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8390 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8391 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8392 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8393 var Cb = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8394 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8395 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8396 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8397 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8398
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8399 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8400 assert_equal(200, a.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8401 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8402 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8403 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8404
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8405 " Test for using a class member as a funcref
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8406 def Test_class_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8407 # Using a funcref class variable in a class method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8408 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8409 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8410 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8411 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8412 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8413
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8414 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8415 static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8416 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8417 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8418 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8419 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8420
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8421 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8422 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8423 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8424
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8425 # Using a funcref class variable in a def method
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8426 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8427 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8428 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8429 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8430 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8431
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8432 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8433 public static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8434 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8435
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8436 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8437 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8438 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8439 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8440 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8441 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8442
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8443 # Using a funcref class variable at script level
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8444 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8445 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8446 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8447 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8448 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8449
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8450 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8451 public static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8452 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8453
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8454 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8455 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8456 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8457
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8458 # Using a funcref class variable pointing to a class method in a class
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8459 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8460 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8461 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8462 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8463 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8464 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8465 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8466 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8467 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8468 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8469 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8470 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8471 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8472 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8473 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8474
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8475 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8476 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8477 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8478 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8479
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8480 # Using a funcref class variable pointing to a class method in a def method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8481 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8482 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8483 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8484 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8485 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8486 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8487 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8488 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8489 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8490 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8491 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8492
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8493 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8494 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8495 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8496 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8497 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8498 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8499 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8500
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8501 # Using a funcref class variable pointing to a class method at script level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8502 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8503 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8504 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8505 static var Cb: func(number): number
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8506 static def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8507 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8508 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8509 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8510 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8511 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8512 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8513
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8514 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8515 assert_equal(200, A.Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8516 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8517 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8518 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8519
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8520 " Test for using object methods as popup callback functions
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8521 def Test_objmethod_popup_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8522 # Use the popup from the script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8523 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8524 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8525
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8526 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8527 var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8528 var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8529
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8530 def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8531 add(this.filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8532 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8533 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8534
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8535 def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8536 this.selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8537 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8538 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8539
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8540 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8541 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8542 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8543 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8544 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8545 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8546 assert_equal(100, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8547 assert_equal(['y'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8548 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8549 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8550 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8551 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8552 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8553 assert_equal(200, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8554 assert_equal(['y', 'n'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8555 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8556 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8557
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8558 # Use the popup from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8559 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8560 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8561
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8562 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8563 var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8564 var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8565
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8566 def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8567 add(this.filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8568 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8569 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8570
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8571 def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8572 this.selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8573 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8574 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8575
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8576 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8577 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8578 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8579 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8580 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8581 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8582 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8583 assert_equal(100, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8584 assert_equal(['y'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8585 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8586 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8587 {filter: a.PopupFilter, callback: a.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8588 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8589 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8590 assert_equal(200, a.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8591 assert_equal(['y', 'n'], a.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8592 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8593 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8594 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8595 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8596 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8597
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8598 " Test for using class methods as popup callback functions
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8599 def Test_classmethod_popup_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8600 # Use the popup from the script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8601 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8602 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8603
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8604 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8605 static var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8606 static var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8607
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8608 static def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8609 add(filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8610 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8611 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8612
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8613 static def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8614 selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8615 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8616 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8617
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8618 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8619 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8620 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8621 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8622 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8623 assert_equal(100, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8624 assert_equal(['y'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8625 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8626 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8627 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8628 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8629 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8630 assert_equal(200, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8631 assert_equal(['y', 'n'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8632 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8633 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8634
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8635 # Use the popup from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8636 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8637 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8638
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8639 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8640 static var selection: number = -1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8641 static var filterkeys: list<string> = []
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8642
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8643 static def PopupFilter(id: number, key: string): bool
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8644 add(filterkeys, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8645 return popup_filter_yesno(id, key)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8646 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8647
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8648 static def PopupCb(id: number, result: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8649 selection = result ? 100 : 200
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8650 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8651 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8652
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8653 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8654 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8655 var winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8656 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8657 feedkeys('y', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8658 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8659 assert_equal(100, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8660 assert_equal(['y'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8661 feedkeys('', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8662 winid = popup_create('Y/N?',
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8663 {filter: A.PopupFilter, callback: A.PopupCb})
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8664 feedkeys('n', 'xt')
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8665 popup_close(winid)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8666 assert_equal(200, A.selection)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8667 assert_equal(['y', 'n'], A.filterkeys)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8668 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8669 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8670 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8671 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8672 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8673
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8674 " Test for using an object method as a timer callback function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8675 def Test_objmethod_timer_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8676 # Use the timer callback from script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8677 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8678 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8679
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8680 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8681 var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8682 def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8683 this.timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8684 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8685 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8686
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8687 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8688 timer_start(0, a.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8689 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8690 while maxWait > 0 && a.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8691 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8692 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8693 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8694 assert_equal(6, a.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8695 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8696 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8697
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8698 # Use the timer callback from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8699 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8700 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8701
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8702 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8703 var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8704 def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8705 this.timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8706 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8707 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8708
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8709 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8710 var a = A.new()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8711 timer_start(0, a.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8712 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8713 while maxWait > 0 && a.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8714 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8715 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8716 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8717 assert_equal(6, a.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8718 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8719 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8720 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8721 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8722 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8723
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8724 " Test for using a class method as a timer callback function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8725 def Test_classmethod_timer_callback()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8726 # Use the timer callback from script level
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8727 var lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8728 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8729
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8730 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8731 static var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8732 static def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8733 timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8734 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8735 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8736
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8737 timer_start(0, A.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8738 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8739 while maxWait > 0 && A.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8740 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8741 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8742 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8743 assert_equal(6, A.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8744 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8745 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8746
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8747 # Use the timer callback from a def function
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8748 lines =<< trim END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8749 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8750
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8751 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8752 static var timerTick: number = -1
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8753 static def TimerCb(timerID: number)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8754 timerTick = 6
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8755 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8756 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8757
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8758 def Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8759 timer_start(0, A.TimerCb)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8760 var maxWait = 5
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8761 while maxWait > 0 && A.timerTick == -1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8762 :sleep 10m
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8763 maxWait -= 1
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8764 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8765 assert_equal(6, A.timerTick)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8766 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8767 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8768 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8769 v9.CheckSourceSuccess(lines)
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8770 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8771
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8772 " Test for using a class variable as the first and/or second operand of a binary
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8773 " operator.
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8774 def Test_class_variable_as_operands()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8775 var lines =<< trim END
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8776 vim9script
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8777 class Tests
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8778 static var truthy: bool = true
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8779 public static var TruthyFn: func
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8780 static var list: list<any> = []
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8781 static var four: number = 4
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8782 static var str: string = 'hello'
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8783
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8784 static def Str(): string
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8785 return str
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8786 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8787
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8788 static def Four(): number
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8789 return four
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8790 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8791
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8792 static def List(): list<any>
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8793 return list
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8794 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8795
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8796 static def Truthy(): bool
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8797 return truthy
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8798 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8799
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8800 def TestOps()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8801 assert_true(Tests.truthy == truthy)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8802 assert_true(truthy == Tests.truthy)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8803 assert_true(Tests.list isnot [])
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8804 assert_true([] isnot Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8805 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8806 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8807 assert_equal(8, Tests.four + four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8808 assert_equal(8, four + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8809 assert_equal('hellohello', Tests.str .. str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8810 assert_equal('hellohello', str .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8811
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8812 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8813 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8814 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8815 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8816
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8817 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8818 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8819 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8820 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8821 endclass
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8822
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8823 def TestOps2()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8824 assert_true(Tests.truthy == Tests.Truthy())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8825 assert_true(Tests.Truthy() == Tests.truthy)
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8826 assert_true(Tests.truthy == Tests.TruthyFn())
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8827 assert_true(Tests.TruthyFn() == Tests.truthy)
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8828 assert_true(Tests.list is Tests.List())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8829 assert_true(Tests.List() is Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8830 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8831 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8832 assert_equal(8, Tests.four + Tests.Four())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8833 assert_equal(8, Tests.Four() + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8834 assert_equal('hellohello', Tests.str .. Tests.Str())
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8835 assert_equal('hellohello', Tests.Str() .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8836
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8837 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8838 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8839 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8840 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8841
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8842 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8843 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8844 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8845 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8846
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8847 Tests.TruthyFn = Tests.Truthy
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8848 var t = Tests.new()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8849 t.TestOps()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8850 TestOps2()
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8851
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8852 assert_true(Tests.truthy == Tests.Truthy())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8853 assert_true(Tests.Truthy() == Tests.truthy)
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8854 assert_true(Tests.truthy == Tests.TruthyFn())
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8855 assert_true(Tests.TruthyFn() == Tests.truthy)
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8856 assert_true(Tests.list is Tests.List())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8857 assert_true(Tests.List() is Tests.list)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8858 assert_equal(2, Tests.four >> 1)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8859 assert_equal(16, 1 << Tests.four)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8860 assert_equal(8, Tests.four + Tests.Four())
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8861 assert_equal(8, Tests.Four() + Tests.four)
33636
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8862 assert_equal('hellohello', Tests.str .. Tests.Str())
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8863 assert_equal('hellohello', Tests.Str() .. Tests.str)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8864
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8865 # Using class variable for list indexing
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8866 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8867 assert_equal(4, l[Tests.four])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8868 assert_equal([4, 5, 6], l[Tests.four : Tests.four + 2])
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8869
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8870 # Using class variable for Dict key
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8871 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8872 assert_equal('abc', d[Tests.str])
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8873 END
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8874 v9.CheckSourceSuccess(lines)
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8875 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8876
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8877 " Test for checking the type of the key used to access an object dict member.
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8878 def Test_dict_member_key_type_check()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8879 var lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8880 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8881
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8882 abstract class State
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8883 var numbers: dict<string> = {0: 'nil', 1: 'unity'}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8884 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8885
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8886 class Test extends State
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8887 def ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8888 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8889 var z: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8890 [this.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8891 assert_equal({0: 'zero.1', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8892 [this.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8893 assert_equal({0: 'zero.2', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8894 [z, this.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8895 assert_equal({0: 'zero.3', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8896 [this.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8897 assert_equal({0: 'zero.4', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8898 [z, this.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8899 assert_equal({0: 'zero.5', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8900 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8901
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8902 static def ClassMethodTests(that: State)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8903 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8904 var z: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8905 [that.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8906 assert_equal({0: 'zero.1', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8907 [that.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8908 assert_equal({0: 'zero.2', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8909 [z, that.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8910 assert_equal({0: 'zero.3', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8911 [that.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8912 assert_equal({0: 'zero.4', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8913 [z, that.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8914 assert_equal({0: 'zero.5', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8915 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8916
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8917 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8918 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8919
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8920 def newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8921 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8922 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8923 [this.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8924 assert_equal({0: 'zero.1', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8925 [this.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8926 assert_equal({0: 'zero.2', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8927 [z, this.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8928 assert_equal({0: 'zero.3', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8929 [this.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8930 assert_equal({0: 'zero.4', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8931 [z, this.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8932 assert_equal({0: 'zero.5', 1: 'unity'}, this.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8933 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8934 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8935
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8936 def DefFuncTests(that: Test)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8937 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8938 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8939 [that.numbers[cursor]] = ['zero.1']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8940 assert_equal({0: 'zero.1', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8941 [that.numbers[string(cursor)], z] = ['zero.2', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8942 assert_equal({0: 'zero.2', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8943 [z, that.numbers[string(cursor)]] = [1, 'zero.3']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8944 assert_equal({0: 'zero.3', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8945 [that.numbers[cursor], z] = ['zero.4', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8946 assert_equal({0: 'zero.4', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8947 [z, that.numbers[cursor]] = [1, 'zero.5']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8948 assert_equal({0: 'zero.5', 1: 'unity'}, that.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8949 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8950
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8951 Test.newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8952 Test.new().ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8953 Test.ClassMethodTests(Test.new())
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8954 DefFuncTests(Test.new())
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8955
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8956 const test: Test = Test.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8957 var cursor: number = 0
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8958 [test.numbers[cursor], cursor] = ['zero', 1]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8959 [cursor, test.numbers[cursor]] = [1, 'one']
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8960 assert_equal({0: 'zero', 1: 'one'}, test.numbers)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8961 END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8962 v9.CheckSourceSuccess(lines)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8963
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8964 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8965 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8966
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8967 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8968 var numbers: dict<string> = {a: '1', b: '2'}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8969
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8970 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8971 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8972
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8973 def Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8974 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8975 [this.numbers.a, z] = [{}, 10]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8976 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8977 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8978
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8979 var a = A.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8980 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8981 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
8982 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected string but got dict<any>', 2)
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8983
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8984 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8985 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8986
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8987 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8988 var numbers: dict<number> = {a: 1, b: 2}
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8989
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8990 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8991 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8992
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8993 def Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8994 var x: string = 'a'
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8995 var y: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8996 [this.numbers[x], y] = [{}, 10]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8997 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8998 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8999
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9000 var a = A.new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9001 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9002 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
9003 v9.CheckSourceFailure(lines, 'E1012: Type mismatch; expected number but got dict<any>', 3)
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9004 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
9005
33829
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9006 def Test_compile_many_def_functions_in_funcref_instr()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9007 # This used to crash Vim. This is reproducible only when run on new instance
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9008 # of Vim.
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9009 var lines =<< trim END
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9010 vim9script
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9011
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9012 class A
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9013 def new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9014 this.TakeFunc(this.F00)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9015 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9016
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9017 def TakeFunc(F: func)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9018 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9019
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9020 def F00()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9021 this.F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9022 this.F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9023 this.F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9024 this.F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9025 this.F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9026 this.F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9027 this.F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9028 this.F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9029 this.F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9030 this.F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9031 this.F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9032 this.F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9033 this.F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9034 this.F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9035 this.F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9036 this.F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9037 this.F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9038 this.F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9039 this.F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9040 this.F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9041 this.F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9042 this.F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9043 this.F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9044 this.F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9045 this.F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9046 this.F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9047 this.F27()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9048 this.F28()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9049 this.F29()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9050 this.F30()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9051 this.F31()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9052 this.F32()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9053 this.F33()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9054 this.F34()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9055 this.F35()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9056 this.F36()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9057 this.F37()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9058 this.F38()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9059 this.F39()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9060 this.F40()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9061 this.F41()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9062 this.F42()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9063 this.F43()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9064 this.F44()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9065 this.F45()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9066 this.F46()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9067 this.F47()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9068 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9069
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9070 def F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9071 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9072 def F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9073 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9074 def F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9075 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9076 def F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9077 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9078 def F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9079 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9080 def F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9081 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9082 def F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9083 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9084 def F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9085 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9086 def F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9087 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9088 def F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9089 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9090 def F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9091 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9092 def F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9093 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9094 def F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9095 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9096 def F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9097 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9098 def F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9099 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9100 def F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9101 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9102 def F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9103 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9104 def F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9105 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9106 def F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9107 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9108 def F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9109 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9110 def F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9111 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9112 def F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9113 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9114 def F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9115 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9116 def F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9117 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9118 def F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9119 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9120 def F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9121 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9122 def F27()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9123 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9124 def F28()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9125 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9126 def F29()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9127 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9128 def F30()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9129 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9130 def F31()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9131 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9132 def F32()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9133 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9134 def F33()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9135 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9136 def F34()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9137 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9138 def F35()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9139 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9140 def F36()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9141 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9142 def F37()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9143 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9144 def F38()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9145 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9146 def F39()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9147 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9148 def F40()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9149 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9150 def F41()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9151 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9152 def F42()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9153 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9154 def F43()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9155 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9156 def F44()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9157 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9158 def F45()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9159 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9160 def F46()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9161 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9162 def F47()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9163 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9164 endclass
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9165
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9166 A.new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9167 END
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9168 writefile(lines, 'Xscript', 'D')
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9169 g:RunVim([], [], '-u NONE -S Xscript -c qa')
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9170 assert_equal(0, v:shell_error)
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9171 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9172
33951
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9173 " Test for 'final' class and object variables
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9174 def Test_final_class_object_variable()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9175 # Test for changing a final object variable from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9176 var lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9177 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9178 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9179 final foo: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9180 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9181 this.foo = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9182 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9183 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9184 defcompile A.Foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9185 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9186 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "foo" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9187
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9188 # Test for changing a final object variable from the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9189 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9190 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9191 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9192 final s1: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9193 final s2: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9194 def new(this.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9195 this.s2 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9196 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9197 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9198 var a = A.new('abc')
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9199 assert_equal('abc', a.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9200 assert_equal('def', a.s2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9201 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9202 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9203
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9204 # Test for a final class variable
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9205 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9206 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9207 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9208 static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9209 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9210 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9211 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9212 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9213
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9214 # Test for changing a final class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9215 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9216 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9217 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9218 static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9219 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9220 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9221 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9222 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9223 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9224 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9225 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9226
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9227 # Test for changing a public final class variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9228 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9229 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9230 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9231 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9232 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9233 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9234 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9235 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9236 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9237
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9238 # Test for changing a public final class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9239 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9240 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9241 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9242 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9243 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9244 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9245 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9246 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9247 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9248 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9249 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9250
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9251 # Test for changing a public final class variable from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9252 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9253 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9254 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9255 public static final s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9256 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9257 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9258 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9259 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9260 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9261 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9262 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9263
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9264 # Test for using a final variable of composite type
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9265 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9266 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9267 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9268 public final l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9269 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9270 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9271 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9272 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9273 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9274 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9275 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9276 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9277 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9278 assert_equal([1, 2], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9279 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9280 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9281 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9282 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9283
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9284 # Test for changing a final variable of composite type from another object
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9285 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9286 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9287 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9288 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9289 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9290 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9291 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9292 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9293 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9294 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9295 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9296 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9297 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9298
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9299 # Test for modifying a final variable of composite type at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9300 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9301 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9302 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9303 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9304 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9305 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9306 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9307 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9308 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9309 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9310 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9311
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9312 # Test for modifying a final variable of composite type from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9313 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9314 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9315 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9316 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9317 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9318 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9319 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9320 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9321 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9322 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9323 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9324 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9325 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9326 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9327
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9328 # Test for modifying a final variable of composite type from another object
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9329 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9330 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9331 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9332 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9333 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9334 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9335 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9336 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9337 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9338 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9339 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9340 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9341 assert_equal([3, 2, 4], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9342 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9343 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9344
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9345 # Test for assigning a new value to a final variable of composite type at
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9346 # script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9347 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9348 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9349 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9350 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9351 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9352 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9353 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9354 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9355 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9356
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9357 # Test for assigning a new value to a final variable of composite type from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9358 # another object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9359 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9360 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9361 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9362 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9363 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9364 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9365 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9366 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9367 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9368 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9369 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9370 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9371
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9372 # Test for assigning a new value to a final variable of composite type from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9373 # another function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9374 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9375 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9376 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9377 public final l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9378 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9379 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9380 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9381 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9382 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9383 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9384 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9385 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9386
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9387 # Error case: Use 'final' with just a variable name
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9388 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9389 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9390 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9391 final foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9392 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9393 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9394 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9395 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9396
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9397 # Error case: Use 'final' followed by 'public'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9398 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9399 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9400 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9401 final public foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9402 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9403 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9404 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9405 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9406
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9407 # Error case: Use 'final' followed by 'static'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9408 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9409 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9410 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9411 final static foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9412 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9413 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9414 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9415 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9416
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9417 # Error case: 'final' cannot be used in an interface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9418 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9419 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9420 interface A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9421 final foo: number = 10
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9422 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9423 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9424 v9.CheckSourceFailure(lines, 'E1408: Final variable not supported in an interface', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9425
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9426 # Error case: 'final' not supported for an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9427 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9428 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9429 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9430 final def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9431 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9432 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9433 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9434 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9435
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9436 # Error case: 'final' not supported for a class method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9437 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9438 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9439 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9440 static final def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9441 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9442 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9443 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9444 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9445 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9446
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9447 " Test for 'const' class and object variables
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9448 def Test_const_class_object_variable()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9449 # Test for changing a const object variable from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9450 var lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9451 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9452 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9453 const foo: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9454 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9455 this.foo = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9456 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9457 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9458 defcompile A.Foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9459 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9460 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "foo" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9461
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9462 # Test for changing a const object variable from the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9463 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9464 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9465 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9466 const s1: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9467 const s2: string
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9468 def new(this.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9469 this.s2 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9470 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9471 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9472 var a = A.new('abc')
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9473 assert_equal('abc', a.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9474 assert_equal('def', a.s2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9475 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9476 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9477
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9478 # Test for changing a const object variable from an object method called from
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9479 # the 'new' function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9480 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9481 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9482 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9483 const s1: string = 'abc'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9484 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9485 this.ChangeStr()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9486 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9487 def ChangeStr()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9488 this.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9489 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9490 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9491 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9492 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9493 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9494
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9495 # Test for a const class variable
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9496 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9497 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9498 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9499 static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9500 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9501 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9502 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9503 v9.CheckSourceSuccess(lines)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9504
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9505 # Test for changing a const class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9506 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9507 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9508 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9509 static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9510 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9511 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9512 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9513 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9514 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9515 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9516 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9517
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9518 # Test for changing a public const class variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9519 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9520 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9521 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9522 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9523 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9524 assert_equal('abc', A.s1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9525 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9526 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9527 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9528
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9529 # Test for changing a public const class variable from a class function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9530 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9531 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9532 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9533 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9534 static def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9535 s1 = "def"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9536 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9537 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9538 A.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9539 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9540 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9541
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9542 # Test for changing a public const class variable from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9543 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9544 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9545 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9546 public static const s1: string = "abc"
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9547 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9548 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9549 A.s1 = 'def'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9550 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9551 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9552 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9553 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "s1" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9554
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9555 # Test for changing a const List item from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9556 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9557 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9558 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9559 public const l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9560 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9561 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9562 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9563 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9564 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9565 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9566 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9567 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9568 assert_equal([1, 2], a.l)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9569 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9570 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9571 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9572
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9573 # Test for adding a value to a const List from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9574 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9575 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9576 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9577 public const l: list<number>
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9578 def new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9579 this.l = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9580 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9581 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9582 this.l->add(3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9583 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9584 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9585 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9586 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9587 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9588 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9589
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9590 # Test for reassigning a const List from an object function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9591 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9592 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9593 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9594 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9595 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9596 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9597 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9598 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9599 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9600 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9601 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9602 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9603
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9604 # Test for changing a const List item at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9605 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9606 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9607 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9608 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9609 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9610 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9611 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9612 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9613 v9.CheckSourceFailure(lines, 'E741: Value is locked:', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9614
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9615 # Test for adding a value to a const List item at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9616 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9617 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9618 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9619 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9620 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9621 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9622 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9623 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9624 v9.CheckSourceFailure(lines, 'E741: Value is locked:', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9625
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9626 # Test for changing a const List item from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9627 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9628 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9629 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9630 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9631 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9632 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9633 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9634 a.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9635 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9636 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9637 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9638 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9639
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9640 # Test for adding a value to a const List item from a function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9641 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9642 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9643 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9644 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9645 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9646 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9647 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9648 a.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9649 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9650 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9651 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9652 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9653
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9654 # Test for changing a const List item from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9655 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9656 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9657 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9658 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9659 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9660 this.l[0] = 3
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9661 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9662 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9663 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9664 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9665 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9666 v9.CheckSourceFailure(lines, 'E1119: Cannot change locked list item', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9667
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9668 # Test for adding a value to a const List item from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9669 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9670 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9671 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9672 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9673 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9674 this.l->add(4)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9675 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9676 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9677 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9678 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9679 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9680 v9.CheckSourceFailure(lines, 'E741: Value is locked: add() argument', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9681
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9682 # Test for reassigning a const List object variable at script level
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9683 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9684 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9685 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9686 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9687 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9688 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9689 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9690 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9691 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 6)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9692
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9693 # Test for reassigning a const List object variable from an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9694 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9695 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9696 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9697 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9698 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9699 this.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9700 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9701 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9702 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9703 a.Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9704 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9705 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 1)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9706
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9707 # Test for reassigning a const List object variable from another function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9708 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9709 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9710 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9711 public const l: list<number> = [1, 2]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9712 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9713 def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9714 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9715 a.l = [3, 4]
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9716 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9717 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9718 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9719 v9.CheckSourceFailure(lines, 'E1409: Cannot change read-only variable "l" in class "A"', 2)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9720
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9721 # Error case: Use 'const' with just a variable name
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9722 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9723 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9724 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9725 const foo
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9726 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9727 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9728 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9729 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9730
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9731 # Error case: Use 'const' followed by 'public'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9732 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9733 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9734 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9735 const public foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9736 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9737 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9738 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9739 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9740
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9741 # Error case: Use 'const' followed by 'static'
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9742 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9743 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9744 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9745 const static foo: number
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9746 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9747 var a = A.new()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9748 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9749 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9750
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9751 # Error case: 'const' cannot be used in an interface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9752 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9753 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9754 interface A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9755 const foo: number = 10
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9756 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9757 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9758 v9.CheckSourceFailure(lines, 'E1410: Const variable not supported in an interface', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9759
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9760 # Error case: 'const' not supported for an object method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9761 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9762 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9763 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9764 const def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9765 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9766 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9767 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9768 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9769
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9770 # Error case: 'const' not supported for a class method
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9771 lines =<< trim END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9772 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9773 class A
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9774 static const def Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9775 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9776 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9777 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9778 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9779 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9780
34112
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9781 " Test for compiling class/object methods using :defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9782 def Test_defcompile_class()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9783 # defcompile all the classes in the current script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9784 var lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9785 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9786 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9787 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9788 var i = 10
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9789 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9790 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9791 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9792 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9793 var i = 20
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9794 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9795 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9796 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9797 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9798 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9799 v9.CheckSourceFailure(lines, 'E476: Invalid command: xxx', 2)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9800
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9801 # defcompile a specific class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9802 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9803 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9804 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9805 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9806 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9807 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9808 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9809 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9810 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9811 yyy
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9812 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9813 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9814 defcompile B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9815 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9816 v9.CheckSourceFailure(lines, 'E476: Invalid command: yyy', 1)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9817
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9818 # defcompile a non-class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9819 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9820 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9821 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9822 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9823 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9824 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9825 var X: list<number> = []
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9826 defcompile X
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9827 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9828 v9.CheckSourceFailure(lines, 'E1061: Cannot find function X', 7)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9829
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9830 # defcompile a class twice
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9831 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9832 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9833 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9834 def new()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9835 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9836 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9837 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9838 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9839 assert_equal('Function A.new does not need compiling', v:statusmsg)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9840 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9841 v9.CheckSourceSuccess(lines)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9842
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9843 # defcompile should not compile an imported class
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9844 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9845 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9846 export class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9847 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9848 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9849 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9850 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9851 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9852 writefile(lines, 'Xdefcompileimport.vim', 'D')
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9853 lines =<< trim END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9854 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9855
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9856 import './Xdefcompileimport.vim'
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9857 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9858 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9859 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9860 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9861 v9.CheckScriptSuccess(lines)
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9862 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9863
34472
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9864 " Test for cases common to all the object builtin methods
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9865 def Test_object_builtin_method()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9866 var lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9867 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9868 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9869 def abc()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9870 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9871 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9872 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9873 v9.CheckSourceFailure(lines, 'E1267: Function name must start with a capital: abc()', 3)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9874
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9875 for funcname in ["len", "string", "empty"]
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9876 lines =<< trim eval END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9877 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9878 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9879 static def {funcname}(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9880 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9881 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9882 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9883 v9.CheckSourceFailure(lines, 'E1413: Builtin class method not supported', 3)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9884 endfor
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9885 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9886
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9887 " Test for using the empty() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9888 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9889 func Test_object_empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9890 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9891 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9892 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9893 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9894 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9895 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9896 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9897
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9898 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9899 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9900 assert_equal(true, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9901 assert_equal(true, afoo->empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9902 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9903
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9904 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9905 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9906 assert_equal(1, a->empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9907 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9908 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9909 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9910 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9911 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9912 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9913 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9914
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9915 " empty() should return 1 without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9916 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9917 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9918 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9919 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9920
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9921 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9922 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9923 assert_equal(1, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9924 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9925
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9926 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9927 assert_equal(1, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9928 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9929 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9930 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9931
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9932 " Unsupported signature for the empty() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9933 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9934 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9935 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9936 def empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9937 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9938 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9939 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9940 call v9.CheckSourceFailure(lines, 'E1383: Method "empty": type mismatch, expected func(): bool but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9941
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9942 " Error when calling the empty() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9943 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9944 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9945 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9946 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9947 throw "Failed to check emptiness"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9948 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9949 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9950
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9951 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9952 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9953 var i = empty(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9954 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9955
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9956 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9957 assert_fails('empty(a)', 'Failed to check emptiness')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9958 assert_fails('Foo()', 'Failed to check emptiness')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9959 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9960 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9961
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9962 " call empty() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9963 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9964 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9965 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9966 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9967 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9968 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9969 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9970 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9971 assert_equal(true, afoo.empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9972 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9973 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9974
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9975 " call empty() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9976 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9977 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9978 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9979 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9980 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9981 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9982 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9983 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9984 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9985 assert_equal(true, afoo.empty())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9986 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9987 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9988 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9989 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9990
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9991 " call empty() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9992 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9993 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9994 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9995 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9996 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9997 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9998 def Foo(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9999 return this.empty()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10000 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10001 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10002 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10003 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10004 assert_equal(true, abar.Foo())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10005 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10006 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10007 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10008 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10009
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10010 " Call empty() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10011 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10012 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10013 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10014 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10015 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10016 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10017 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10018 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10019 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10020 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10021 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10022 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10023 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10024 assert_equal(true, empty(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10025 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10026 assert_equal(true, empty(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10027 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10028 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10029 assert_equal(1, empty(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10030 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10031 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10032 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10033
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10034 " Invoking empty method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10035 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10036 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10037 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10038 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10039 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10040 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10041 def empty(): bool
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10042 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10043 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10044 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10045 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10046 assert_equal(false, empty(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10047 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10048 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10049 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10050 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10051 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10052 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10053
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10054 " Test for using the len() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10055 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10056 func Test_object_length()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10057 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10058 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10059 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10060 var mylen: number = 0
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10061 def new(n: number)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10062 this.mylen = n
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10063 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10064 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10065 return this.mylen
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10066 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10067 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10068
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10069 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10070 var afoo = A.new(12)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10071 assert_equal(12, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10072 assert_equal(12, afoo->len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10073 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10074
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10075 var a = A.new(22)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10076 assert_equal(22, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10077 assert_equal(22, a->len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10078 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10079 assert_equal(22, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10080 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10081 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10082 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10083 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10084 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10085
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10086 " len() should return 0 without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10087 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10088 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10089 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10090 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10091
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10092 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10093 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10094 assert_equal(0, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10095 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10096
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10097 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10098 assert_equal(0, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10099 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10100 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10101 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10102
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10103 " Unsupported signature for the len() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10104 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10105 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10106 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10107 def len()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10108 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10109 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10110 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10111 call v9.CheckSourceFailure(lines, 'E1383: Method "len": type mismatch, expected func(): number but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10112
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10113 " Error when calling the len() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10114 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10115 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10116 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10117 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10118 throw "Failed to compute length"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10119 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10120 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10121
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10122 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10123 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10124 var i = len(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10125 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10126
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10127 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10128 assert_fails('len(a)', 'Failed to compute length')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10129 assert_fails('Foo()', 'Failed to compute length')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10130 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10131 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10132
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10133 " call len() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10134 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10135 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10136 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10137 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10138 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10139 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10140 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10141 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10142 assert_equal(5, afoo.len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10143 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10144 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10145
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10146 " call len() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10147 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10148 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10149 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10150 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10151 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10152 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10153 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10154 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10155 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10156 assert_equal(5, afoo.len())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10157 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10158 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10159 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10160 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10161
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10162 " call len() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10163 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10164 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10165 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10166 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10167 return 8
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10168 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10169 def Foo(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10170 return this.len()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10171 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10172 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10173 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10174 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10175 assert_equal(8, abar.Foo())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10176 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10177 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10178 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10179 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10180
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10181 " Call len() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10182 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10183 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10184 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10185 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10186 return 10
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10187 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10188 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10189 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10190 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10191 return 20
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10192 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10193 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10194 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10195 assert_equal(20, len(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10196 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10197 assert_equal(20, len(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10198 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10199 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10200 assert_equal(20, len(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10201 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10202 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10203 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10204
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10205 " Invoking len method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10206 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10207 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10208 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10209 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10210 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10211 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10212 def len(): number
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10213 return 123
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10214 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10215 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10216 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10217 assert_equal(123, len(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10218 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10219 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10220 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10221 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10222 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10223 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10224
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10225 " Test for using the string() builtin method with an object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10226 " This is a legacy function to use the test_garbagecollect_now() function.
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10227 func Test_object_string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10228 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10229 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10230 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10231 var name: string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10232 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10233 return this.name
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10234 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10235 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10236
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10237 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10238 var afoo = A.new("foo-A")
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10239 assert_equal('foo-A', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10240 assert_equal('foo-A', afoo->string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10241 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10242
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10243 var a = A.new("script-A")
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10244 assert_equal('script-A', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10245 assert_equal('script-A', a->string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10246 assert_equal(['script-A'], execute('echo a')->split("\n"))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10247 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10248 assert_equal('script-A', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10249 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10250 test_garbagecollect_now()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10251 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10252 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10253 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10254
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10255 " string() should return "object of A {}" without a builtin method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10256 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10257 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10258 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10259 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10260
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10261 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10262 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10263 assert_equal('object of A {}', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10264 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10265
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10266 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10267 assert_equal('object of A {}', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10268 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10269 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10270 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10271
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10272 " Unsupported signature for the string() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10273 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10274 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10275 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10276 def string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10277 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10278 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10279 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10280 call v9.CheckSourceFailure(lines, 'E1383: Method "string": type mismatch, expected func(): string but got func()', 4)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10281
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10282 " Error when calling the string() method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10283 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10284 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10285 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10286 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10287 throw "Failed to get text"
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10288 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10289 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10290
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10291 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10292 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10293 var i = string(afoo)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10294 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10295
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10296 var a = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10297 assert_fails('string(a)', 'Failed to get text')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10298 assert_fails('Foo()', 'Failed to get text')
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10299 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10300 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10301
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10302 " call string() using an object from a script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10303 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10304 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10305 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10306 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10307 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10308 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10309 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10310 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10311 assert_equal('A', afoo.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10312 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10313 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10314
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10315 " call string() using an object from a method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10316 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10317 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10318 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10319 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10320 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10321 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10322 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10323 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10324 var afoo = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10325 assert_equal('A', afoo.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10326 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10327 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10328 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10329 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10330
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10331 " call string() using "this" from an object method
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10332 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10333 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10334 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10335 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10336 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10337 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10338 def Foo(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10339 return this.string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10340 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10341 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10342 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10343 var abar = A.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10344 assert_equal('A', abar.string())
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10345 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10346 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10347 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10348 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10349
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10350 " Call string() from a derived object
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10351 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10352 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10353 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10354 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10355 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10356 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10357 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10358 class B extends A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10359 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10360 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10361 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10362 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10363 def Foo(afoo: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10364 assert_equal('B', string(afoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10365 var bfoo = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10366 assert_equal('B', string(bfoo))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10367 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10368 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10369 assert_equal('B', string(b))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10370 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10371 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10372 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10373
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10374 " Invoking string method using an interface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10375 let lines =<< trim END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10376 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10377 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10378 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10379 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10380 class B implements A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10381 def string(): string
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10382 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10383 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10384 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10385 def Foo(a: A)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10386 assert_equal('B', string(a))
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10387 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10388 var b = B.new()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10389 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10390 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10391 call v9.CheckSourceSuccess(lines)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10392 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10393
34508
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10394 " Test for using a class in the class definition
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10395 def Test_Ref_Class_Within_Same_Class()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10396 var lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10397 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10398 class A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10399 var n: number = 0
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10400 def Equals(other: A): bool
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10401 return this.n == other.n
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10402 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10403 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10404
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10405 var a1 = A.new(10)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10406 var a2 = A.new(10)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10407 var a3 = A.new(20)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10408 assert_equal(true, a1.Equals(a2))
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10409 assert_equal(false, a2.Equals(a3))
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10410 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10411 v9.CheckScriptSuccess(lines)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10412
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10413 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10414 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10415
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10416 class Foo
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10417 var num: number
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10418 def Clone(): Foo
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10419 return Foo.new(this.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10420 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10421 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10422
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10423 var f1 = Foo.new(1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10424
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10425 def F()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10426 var f2: Foo = f1.Clone()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10427 assert_equal(false, f2 is f1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10428 assert_equal(true, f2.num == f1.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10429 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10430 F()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10431
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10432 var f3: Foo = f1.Clone()
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10433 assert_equal(false, f3 is f1)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10434 assert_equal(true, f3.num == f1.num)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10435 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10436 v9.CheckScriptSuccess(lines)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10437
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10438 # Test for trying to use a class to extend when defining the same class
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10439 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10440 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10441 class A extends A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10442 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10443 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10444 v9.CheckScriptFailure(lines, 'E1354: Cannot extend A', 3)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10445
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10446 # Test for trying to use a class to implement when defining the same class
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10447 lines =<< trim END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10448 vim9script
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10449 class A implements A
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10450 endclass
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10451 END
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10452 v9.CheckScriptFailure(lines, 'E1347: Not a valid interface: A', 3)
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10453 enddef
d7b7fa7edb3b patch 9.1.0160: Vim9: Add support for using a class type of itself in an object method
Christian Brabandt <cb@256bit.org>
parents: 34472
diff changeset
10454
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10455 " Test for using a compound operator from a lambda function in an object method
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10456 def Test_compound_op_in_objmethod_lambda()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10457 # Test using the "+=" operator
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10458 var lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10459 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10460 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10461 var n: number = 10
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10462 def Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10463 var Fn = () => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10464 this.n += 1
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10465 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10466 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10467 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10468 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10469
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10470 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10471 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10472 assert_equal(11, a.n)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10473 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10474 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10475
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10476 # Test using the "..=" operator
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10477 lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10478 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10479 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10480 var s: string = "a"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10481 def Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10482 var Fn = () => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10483 this.s ..= "a"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10484 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10485 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10486 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10487 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10488
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10489 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10490 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10491 a.Foo()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10492 assert_equal("aaa", a.s)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10493 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10494 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10495 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10496
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10497 " Test for using test_refcount() with a class and an object
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10498 def Test_class_object_refcount()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10499 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10500 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10501 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10502 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10503 var a: A = A.new()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10504 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10505 assert_equal(1, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10506 var b = a
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10507 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10508 assert_equal(2, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10509 assert_equal(2, test_refcount(b))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10510 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10511 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10512 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10513
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10514 " call a lambda function in one object from another object
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10515 def Test_lambda_invocation_across_classes()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10516 var lines =<< trim END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10517 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10518 class A
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10519 var s: string = "foo"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10520 def GetFn(): func
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10521 var Fn = (): string => {
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10522 return this.s
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10523 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10524 return Fn
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10525 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10526 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10527
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10528 class B
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10529 var s: string = "bar"
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10530 def GetFn(): func
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10531 var a = A.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10532 return a.GetFn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10533 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10534 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10535
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10536 var b = B.new()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10537 var Fn = b.GetFn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10538 assert_equal("foo", Fn())
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10539 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10540 v9.CheckScriptSuccess(lines)
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10541 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10542
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10543 " Test for using a class member which is an object of the current class
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10544 def Test_current_class_object_class_member()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10545 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10546 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10547 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10548 public static var obj1: A = A.new(10)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10549 var n: number
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10550 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10551 defcompile
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10552 assert_equal(10, A.obj1.n)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10553 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10554 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10555 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10556
34748
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10557 " Test for updating a base class variable from a base class method without the
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10558 " class name. This used to crash Vim (Github issue #14352).
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10559 def Test_use_base_class_variable_from_base_class_method()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10560 var lines =<< trim END
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10561 vim9script
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10562
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10563 class DictKeyClass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10564 static var _obj_id_count = 1
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10565 def _GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10566 _obj_id_count += 1
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10567 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10568 static def GetIdCount(): number
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10569 return _obj_id_count
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10570 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10571 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10572
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10573 class C extends DictKeyClass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10574 def F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10575 this._GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10576 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10577 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10578
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10579 C.new().F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10580 assert_equal(2, DictKeyClass.GetIdCount())
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10581 END
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10582 v9.CheckScriptSuccess(lines)
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10583 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10584
34769
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10585 " Test for accessing protected funcref object and class variables
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10586 def Test_protected_funcref()
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10587 # protected funcref object variable
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10588 var lines =<< trim END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10589 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10590 class Test1
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10591 const _Id: func(any): any = (v) => v
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10592 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10593 var n = Test1.new()._Id(1)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10594 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10595 v9.CheckScriptFailure(lines, 'E1333: Cannot access protected variable "_Id" in class "Test1"', 5)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10596
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10597 # protected funcref class variable
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10598 lines =<< trim END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10599 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10600 class Test2
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10601 static const _Id: func(any): any = (v) => v
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10602 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10603 var n = Test2._Id(2)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10604 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10605 v9.CheckScriptFailure(lines, 'E1333: Cannot access protected variable "_Id" in class "Test2"', 5)
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10606 enddef
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10607
34773
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10608 " Test for using lambda block in classes
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10609 def Test_lambda_block_in_class()
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10610 # This used to crash Vim
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10611 var lines =<< trim END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10612 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10613 class IdClass1
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10614 const Id: func(number): number = (num: number): number => {
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10615 # Return a ID
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10616 return num * 10
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10617 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10618 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10619 var id = IdClass1.new()
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10620 assert_equal(20, id.Id(2))
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10621 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10622 v9.CheckScriptSuccess(lines)
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10623
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10624 # This used to crash Vim
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10625 lines =<< trim END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10626 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10627 class IdClass2
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10628 static const Id: func(number): number = (num: number): number => {
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10629 # Return a ID
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10630 return num * 2
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10631 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10632 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10633 assert_equal(16, IdClass2.Id(8))
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10634 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10635 v9.CheckScriptSuccess(lines)
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10636 enddef
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10637
34834
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10638 " Test for defcompiling an abstract method
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10639 def Test_abstract_method_defcompile()
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10640 # Compile an abstract class with abstract object methods
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10641 var lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10642 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10643 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10644 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10645 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10646 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10647 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10648 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10649 v9.CheckScriptSuccess(lines)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10650
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10651 # Compile a concrete object method in an abstract class
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10652 lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10653 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10654 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10655 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10656 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10657 def Baz(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10658 pass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10659 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10660 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10661 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10662 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10663 v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10664
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10665 # Compile a concrete class method in an abstract class
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10666 lines =<< trim END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10667 vim9script
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10668 abstract class A
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10669 abstract def Foo(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10670 abstract def Bar(): list<string>
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10671 static def Baz(): string
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10672 pass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10673 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10674 endclass
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10675 defcompile
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10676 END
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10677 v9.CheckScriptFailure(lines, 'E476: Invalid command: pass', 1)
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10678 enddef
d3127b18fe1e patch 9.1.0286: Vim9: E1027 with defcompile for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 34773
diff changeset
10679
34907
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10680 " Test for defining a class in a function
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10681 def Test_class_definition_in_a_function()
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10682 var lines =<< trim END
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10683 vim9script
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10684 def Foo()
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10685 class A
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10686 endclass
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10687 enddef
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10688 defcompile
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10689 END
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10690 v9.CheckScriptFailure(lines, 'E1429: Class can only be used in a script', 1)
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10691 enddef
8c9e43278b2c patch 9.1.0314: Vim9: Can define a class in a function
Christian Brabandt <cb@256bit.org>
parents: 34834
diff changeset
10692
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
10693 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker