annotate src/testdir/test_vim9_class.vim @ 34773:af48c532bd88 v9.1.0263

patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes Commit: https://github.com/vim/vim/commit/3fa8f7728a47822e4efd106ab30c83c28f198b3c Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Thu Apr 4 21:42:07 2024 +0200 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes Problem: Vim9: Problem with lambda blocks in enums and classes (Aliaksei Budavei) Solution: Support evaluating lambda blocks from a string, skip over comments (Yegappan Lakshmanan) fixes: #14350 closes: #14405 Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 04 Apr 2024 22:00:04 +0200
parents d4fb6ea26ae4
children d3127b18fe1e
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
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
70 # 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
71 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
72 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
73 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
74 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
75 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
76 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
77 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
78 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
79 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
80 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
81 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
82 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
83 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
84 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
85
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
86 # 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
87 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
88 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
89 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
90 this.count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
91 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
92 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
93 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
94
34344
be4389b04043 patch 9.1.0105: Style: typos found
Christian Brabandt <cb@256bit.org>
parents: 34112
diff changeset
95 # 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
96 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
97 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
98 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
99 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
100 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
101 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
102 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
103
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
104 # 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
105 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
106 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
107 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
108 this.count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
109 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
110 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
111 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
112
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
113 # Use "this" without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
114 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
115 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
116 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
117 this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
118 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
119 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
120 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
121
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
122 # Use "this." without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
123 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
124 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
125 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
126 this.
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
127 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
128 END
33942
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.', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
130
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
131 # Space between "this" and ".<variable>"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
132 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
133 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
134 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
135 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
136 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
137 END
33942
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', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
139
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
140 # Space between "this." and the member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
141 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
142 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
143 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
144 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
145 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
146 END
33942
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', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
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 "that" instead of "this"
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
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
153 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
154 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
155 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
156 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
157 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
158
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
159 # 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
160 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
161 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
162 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
163 variable count: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
164 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
165 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
166 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
167
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
168 # 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
169 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
170 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
171 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
172 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
173 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
174 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
175 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
176
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
177 # 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
178 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
179 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
180 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
181 variable count = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
182 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
183 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
184 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
185
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
186 # Use a non-existing member variable in new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
187 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
188 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
189 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
190 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
191 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
192 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
193 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
194 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
195 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
196 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
197
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
198 # Space before ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
199 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
200 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
201 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
202 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
203 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
204 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
205 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
206
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
207 # No space after ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
208 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
209 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
210 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
211 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
212 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
213 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
214 v9.CheckSourceFailure(lines, "E1069: White space required after ':'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
215
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
216 # 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
217 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
218 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
219 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
220 var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
221 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
222 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
223 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
224
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
225 # 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
226 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
227 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
228 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
229 var: number = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
230 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
231 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
232 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
233
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
234 # 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
235 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
236 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
237 class Something
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
238 var = 42
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
239 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
240 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
241 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
242
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
243 # 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
244 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
245 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
246 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
247 # 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
248 #{
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
249 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
250 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
251 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
252
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
253 # 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
254 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
255 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
256 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
257 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
258 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
259 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
260 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
261 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
262
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
263 # 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
264 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
265 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
266 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
267 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
268 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
269 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
270 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
271 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
272 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
273
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
274 # 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
275 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
276 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
277 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
278 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
279 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
280 END
33933
aceaf677dd92 patch 9.0.2163: Vim9: type can be assigned to list/dict
Christian Brabandt <cb@256bit.org>
parents: 33929
diff changeset
281 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
282
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
283 # 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
284 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
285 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
286 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
287 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
288 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
289 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
290 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
291 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
292
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
293 # 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
294 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
295 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
296 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
297 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
298 :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
299 END
34006
ab6a70fad5b5 patch 9.0.2184: Vim9: inconsistent :type/:class messages
Christian Brabandt <cb@256bit.org>
parents: 33996
diff changeset
300 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
301
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
302 # 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
303 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
304 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
305 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
306 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
307 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
308 :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
309 END
33678
7d9d2404a3d4 patch 9.0.2076: Vim9: No support for type aliases
Christian Brabandt <cb@256bit.org>
parents: 33668
diff changeset
310 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
311
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
312 # 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
313 # 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
314 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
315 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
316
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
317 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
318 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
319 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
320
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
321 # 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
322 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
323 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
324 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
325 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
326
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
327 # 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
328 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
329 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
330 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
331
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
332 # 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
333 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
334
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
335 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
336 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
337 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
338 assert_equal('object<TextPosition>', typename(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
339 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
340 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
341
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
342 # 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
343 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
344 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
345 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
346 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
347 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
348 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
349 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
350 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
351 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
352 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
353 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
354
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
355 # 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
356 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
357 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
358 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
359 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
360 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
361 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
362 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
363 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
364 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
365 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
366 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
367
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
368 # 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
369 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
370 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
371 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
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
380 # 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
381 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
382 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
383 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
384 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
385 X: 1
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
386 }
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
387 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
388 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
389 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
390 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
391 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
392
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
393 " 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
394 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
395 # 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
396 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
397 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
398 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
399 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
400 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
401 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
402 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
403 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "var" or "static"', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
404
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
405 # 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
406 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
407 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
408 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
409 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
410 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
411 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
412 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
413 v9.CheckSourceFailure(lines, 'E1388: Public keyword not supported for a method', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
414
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
415 # 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
416 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
417 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
418 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
419 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
420 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
421 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
422 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
423 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "var" or "static"', 3)
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
424
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
425 # 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
426 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
427 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
428 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
429 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
430 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
431 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
432 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
433 v9.CheckSourceFailure(lines, 'E1388: Public keyword not supported for a method', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
434
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
435 # 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
436 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
437 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
438 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
439 def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
440 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
441 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
442 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
443 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
444
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
445 # 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
446 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
447 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
448 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
449 static def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
450 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
451 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
452 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
453 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
454 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
455
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
456 def Test_class_defined_twice()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
457 # class defined twice should fail
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
458 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
459 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
460 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
461 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
462 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
463 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
464 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
465 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "There"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
466
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
467 # one class, reload same script twice is OK
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
468 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
469 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
470 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
471 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
472 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
473 writefile(lines, 'XclassTwice.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
474 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
475 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
476 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
477
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
478 def Test_returning_null_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
479 # this was causing an internal error
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
480 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
481 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
482
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
483 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
484 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
485 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
486 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
487 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
488
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
489 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
490 echo buffers.Current()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
491 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
492 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
493 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
494
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
495 def Test_using_null_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
496 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
497 @_ = 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
498 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
499 v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
500 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
501
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
502 def Test_class_interface_wrong_end()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
503 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
504 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
505 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
506 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
507 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
508 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
509 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
510
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
511 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
512 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
513 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
514 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
515 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
516 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
517 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
518 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
519
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
520 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
521 # Use an uninitialized object in script context
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
522 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
523 vim9script
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 class State
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
526 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
527 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
528
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
529 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
530 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
531 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
532 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
533 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
534
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
535 # Use an uninitialized object from a def function
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
536 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
537 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
538
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
539 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
540 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
541 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
542 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
543 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
544 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
545
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
546 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
547 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
548 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
549 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
550 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
551 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
552 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
553
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
554 # 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
555 # object method.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
556 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
557 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
558
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
559 class Background
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
560 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
561 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
562
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
563 class Colorscheme
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
564 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
565
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
566 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
567 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
568 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
569 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
570
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
571 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
572 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
573 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
574 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
575
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
576 # 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
577 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
578 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
579
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
580 class Class
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
581 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
582 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
583 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
584 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
585 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
586
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
587 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
588 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
589 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
590 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
591 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
592 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
593 v9.CheckSourceFailure(lines, 'E1363: Incomplete type', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
594 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
595
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
596 " 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
597 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
598 var lines =<< trim END
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
599 vim9script
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
600
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
601 var nullo = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
602 def F(): any
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
603 return nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
604 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
605 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
606
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
607 var o0 = F()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
608 assert_true(o0 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
609 assert_true(o0 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
610
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
611 var o1: any = nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
612 assert_true(o1 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
613 assert_true(o1 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
614
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
615 def G()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
616 var x = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
617 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
618
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
619 class C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
620 endclass
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
621 var o2: C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
622 assert_true(o2 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
623 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
624
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
625 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
626 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
627
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
628 o2 = C.new()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
629 assert_true(o2 != null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
630
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
631 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
632 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
633 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
634 v9.CheckSourceSuccess(lines)
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
635 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
636
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
637 " Test for object member initialization and disassembly
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
638 def Test_class_member_initializer()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
639 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
640 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
641
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
642 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
643 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
644 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
645
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
646 # 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
647 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
648 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
649 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
650 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
651
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
652 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
653 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
654 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
655
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
656 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
657 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
658 '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
659 '\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
660 '\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
661 '\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
662 '\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
663 '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
664 '\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
665 '\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
666 '\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
667 '\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
668 '\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
669 instr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
670 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
671 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
672 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
673
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
674 def Test_member_any_used_as_object()
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 Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
679 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
680 endclass
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 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
683 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
684 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
685
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
686 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
687 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
688 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
689
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
690 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
691 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
692 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
693 assert_equal(1, inner_obj.value)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
694 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
695 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
696
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
697 # 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
698 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
699 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
700
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
701 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
702 var _value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
703 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
704
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
705 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
706 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
707 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
708
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
709 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
710 outer.inner._value = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
711 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
712
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
713 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
714 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
715 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
716 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
717 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
718
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
719 # 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
720 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
721 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
722
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
723 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
724 var value: string = ''
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
725 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
726
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
727 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
728 var inner: any
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
729 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
730
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
731 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
732 outer.inner.someval = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
733 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
734
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
735 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
736 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
737 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
738 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
739 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
740 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
741
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
742 " 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
743 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
744 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
745 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
746
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
747 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
748 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
749 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
750
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
751 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
752 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
753 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
754
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
755 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
756 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
757 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
758
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
759 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
760 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
761 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
762 F(outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
763 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
764 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
765
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
766 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
767
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
768 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
769 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
770 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
771 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
772 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
773 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
774
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
775 # 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
776 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
777 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
778
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
779 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
780 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
781 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
782
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
783 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
784 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
785 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
786
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
787 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
788 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
789 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
790
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
791 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
792 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
793 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
794 F(outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
795 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
796 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
797
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
798 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
799 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
800 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
801
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
802 # 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
803 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
804 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
805
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
806 class Inner
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
807 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
808 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
809
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
810 class Outer
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
811 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
812 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
813
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
814 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
815 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
816 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
817
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
818 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
819 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
820 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
821 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
822 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
823 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
824 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
825
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
826 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
827 # Use "+=" to assign to a object variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
828 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
829 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
830
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
831 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
832 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
833
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
834 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
835 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
836 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
837 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
838
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
839 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
840 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
841 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
842
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
843 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
844 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
845 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
846
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
847 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
848 assert_equal(23, f.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
849 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
850 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
851 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
852
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
853 def Test_list_of_objects()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
854 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
855 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
856
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
857 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
858 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
859 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
860 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
861
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
862 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
863 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
864 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
865 endfor
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
866 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
867
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
868 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
869 ProcessList(l)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
870 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
871 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
872 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
873
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
874 def Test_expr_after_using_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
875 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
876 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
877
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
878 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
879 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
880 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
881
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
882 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
883 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
884 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
885 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
886 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
887
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
888 Foo()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
889 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
890 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
891 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
892
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
893 def Test_class_default_new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
894 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
895 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
896
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
897 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
898 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
899 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
900 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
901
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
902 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
903 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
904 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
905
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
906 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
907 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
908 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
909
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
910 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
911 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
912 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
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 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
915 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
916 assert_equal(33, pos.col)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
917 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
918 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
919
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
920 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
921 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
922 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
923 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
924 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
925 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
926
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
927 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
928 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
929 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
930
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
931 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
932 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
933 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
934 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
935
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
936 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
937 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
938 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
939 assert_equal("none", chris.education)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
940 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
941 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
942
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
943 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
944 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
945 class Person
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
946 var name: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
947 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
948 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
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 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
951 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
952 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
953
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
954 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
955 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
956 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
957
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
958 # 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
959 # method.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
960 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
961 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
962 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
963 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
964 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
965 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
966 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
967 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
968 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
969 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
970
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
971 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
972 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
973 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
974
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
975 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
976 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
977 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
978 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
979 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
980 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
981 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
982 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
983
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
984 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
985 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
986 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
987 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
988 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
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 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
991 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
992 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
993 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
994 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
995 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
996 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
997
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
998 Check()
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
999 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1000 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1001
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1002 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
1003 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
1004
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
1005 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1006 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1007 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
1008 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
1009 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1010 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1011
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1012 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
1013 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1014 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
1015 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1016 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
1017 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1018 enddef
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 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 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1022 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
1023
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1024 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
1025 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1026
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1027 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1028 var str: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1029 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
1030 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
1031 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1032 endclass
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 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
1035 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1036 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
1037 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1038 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
1039 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1040 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1041
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1042 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1043 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1044 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
1045
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1046 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
1047 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1048
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1049 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1050 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
1051 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
1052 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1053 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1054
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1055 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
1056 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1057 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
1058 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1059 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
1060 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1061 enddef
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 Check()
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1064 END
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
1065 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
1066
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1067 # 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
1068 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
1069 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1070 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1071 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
1072 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
1073 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1074 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1075 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1076 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
1077
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1078 # 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
1079 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
1080 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1081 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1082 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
1083 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
1084 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1085 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1086 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1087 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
1088 enddef
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1089
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1090 def Test_class_object_member_inits()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1091 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
1092 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1093 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1094 var lnum: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1095 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1096 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
1097 endclass
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 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
1100 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
1101 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
1102 assert_equal(2, pos.addcol)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1103 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1104 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1105
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1106 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
1107 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1108 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1109 var lnum
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1110 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
1111 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1112 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1113 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1114
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1115 # 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
1116 # object creation and not when defining the class.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1117 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
1118 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1119
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1120 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
1121 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
1122 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
1123 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
1124 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1125
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1126 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1127 var str1 = Init()
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1128 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
1129 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
1130 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1132 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
1133 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
1134 assert_equal(init_count, 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1135 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1136 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
1137
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1138 # 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
1139 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
1140 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
1141 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1142 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
1143 endclass
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1144 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
1145 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
1146 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
1147
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1148 # 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
1149 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
1150 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1151 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1152 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
1153 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1154 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
1155 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
1156 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1157
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1158 " 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
1159 def Test_instance_variable_access()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1160 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
1161 vim9script
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 Triple
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1163 var _one = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1164 var two = 2
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1165 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
1166
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1167 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
1168 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
1169 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1170 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1171
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1172 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
1173 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
1174 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
1175 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
1176 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
1177
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1178 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
1179 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
1180 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
1181 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
1182
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1183 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
1184 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1185 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1186
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
1187 # 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
1188 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
1189 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
1190 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1191 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
1192 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1193 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1194 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
1195
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1196 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
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1199 class MyCar
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1200 var make: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1201 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
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 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
1204 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
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1207 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
1208 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
1209 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1210 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
1211 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
1212 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1213 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1214
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1215 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
1216 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
1217
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1218 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
1219 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
1220
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1221 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
1222 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
1223
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1224 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
1225 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
1226 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
1227 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1228 CheckCar()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1229 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1230 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1231
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1232 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
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
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1237
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1238 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
1239 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
1240 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1241 endclass
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 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
1244 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
1245 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1246 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
1247
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1248 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
1249 vim9script
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 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1252 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
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 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
1255 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
1256 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
1257 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1258 endclass
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 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
1261 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
1262 .x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1263 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
1264 .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
1265 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
1266 .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
1267 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
1268 .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
1269 .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
1270 .x
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1271 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1272 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
1273
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1274 # 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
1275 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
1276 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
1277 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1278 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
1279 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1280 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1281 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
1282
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1283 # 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
1284 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
1285 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
1286 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
1287 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
1288 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
1289 END
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1290 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
1291
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1292 # 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
1293 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1294 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1295 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1296 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
1297 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1298 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1299 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
1300 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
1301
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1302 # 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
1303 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
1304 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1305 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1306 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
1307 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1308 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1309 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
1310 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
1311
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1312 # 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
1313 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
1314 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1315 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1316 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
1317 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1318 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1319 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1320 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1321 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1322 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
1323 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
1324
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1325 # 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
1326 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1327 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1328 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1329 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
1330 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1331 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1332 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1333 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1334 T()
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', 1)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1337
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1338 # 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
1339 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
1340 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
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 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
1343 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
1344 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
1345 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1346
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1347 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
1348 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
1349 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
1350 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
1351 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
1352 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
1353 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
1354 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
1355 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
1356 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1357 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1358
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1359 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
1360 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1361 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1362 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1363 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1364
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1365 " 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
1366 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
1367 # 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
1368 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1369 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1370 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1371 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
1372 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1373 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1374 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
1375
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1376 # 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
1377 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1378 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1379 class Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1380 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
1381 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1382 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1383 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
1384
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1385 # 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
1386 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
1387 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1388 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1389 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
1390 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1391
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1392 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
1393 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
1394 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
1395 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1396 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1397
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1398 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
1399 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
1400 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1401 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
1402
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1403 # 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
1404 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
1405 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1406 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1407 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
1408 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1409
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1410 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
1411 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
1412 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
1413 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1414 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1415
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1416 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
1417 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
1418 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1419 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
1420
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1421 # 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
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 _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
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._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
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
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1437 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
1438
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1439 # 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
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 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
1444 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
1445 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
1446 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1447
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1448 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
1449 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
1450 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
1451 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
1452 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
1453 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
1454 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
1455 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
1456 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
1457 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1458 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1459
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1460 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
1461 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
1462 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
1463 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
1464 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
1465 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1466 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1467 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1468 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1469
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1470 def Test_class_object_compare()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1471 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
1472 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1473 class Item
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1474 var nr = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1475 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
1476 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1477 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1478
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1479 # used at the script level and in a compiled function
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1480 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
1481 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
1482 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
1483 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
1484 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
1485 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
1486 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
1487 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
1488 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
1489
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1490 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
1491 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
1492 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
1493 assert_notequal(i1, io2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1494 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1495
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1496 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
1497 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
1498 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1499
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1500 for op in ['>', '>=', '<', '<=', '=~', '!~']
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1501 var op_lines = [
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1502 'var i1 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1503 'var i2 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1504 'echo i1 ' .. op .. ' i2',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1505 ]
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1506 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
1507 v9.CheckSourceFailure(class_lines
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1508 + ['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
1509 endfor
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1510 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1511
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1512 def Test_object_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1513 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
1514 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1515
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1516 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1517 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
1518 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1519 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1520 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
1521 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1522 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
1523 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
1524 endclass
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 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
1527 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
1528 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
1529 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
1530
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1531 t = m
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1532 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1533 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1534
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1535 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
1536 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1537
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1538 class One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1539 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
1540 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1541 class Two
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1542 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
1543 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1544
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1545 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
1546 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1547 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
1548
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1549 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
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 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
1553 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
1554 endinterface
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 implements One
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1556 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
1557 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
1558 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
1559 enddef
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 = 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
1563 assert_equal(5, o.GetMember())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1564 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1565 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1566
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1567 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
1568 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1569
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1570 class Num
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1571 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
1572 endclass
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 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
1575 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
1576 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
1577 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1578 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1579
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1580 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
1581 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
1582
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1583 echo Fn(Num.new(4))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1584 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1585 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1586 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1587
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1588 def Test_class_member()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1589 # check access rules
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1590 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
1591 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1592 class TextPos
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1593 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1594 var col = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1595 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
1596 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
1597 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
1598
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1599 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
1600 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
1601 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1602 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1603
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1604 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
1605 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
1606 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
1607 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
1608
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1609 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
1610 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
1611 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1612 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
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 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
1615 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
1616 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
1617
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1618 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
1619 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
1620
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1621 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
1622 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
1623 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
1624 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
1625 assert_equal(17, TextPos.anybody)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1626 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1627 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1628
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1629 # example in the help
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1630 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
1631 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1632 class OtherThing
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1633 var size: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1634 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
1635
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1636 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
1637 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
1638 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1639 endclass
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, 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
1641 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
1642 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
1643 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
1644 assert_equal(10, OtherThing.totalSize)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1645 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1646 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1647
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1648 # using static class member twice
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1649 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
1650 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1651
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1652 class HTML
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1653 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
1654
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1655 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
1656 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
1657 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1658 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1659
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1660 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
1661 assert_equal('some text', HTML.MacroSubstitute('some text'))
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
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1665 # access protected member in lambda
32670
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1669 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1670 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
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 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
1673 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
1674 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
1675 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1676 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1677
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1678 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
1679 assert_equal(5, foo.Add(5))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1680 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1681 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1682
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1683 # access protected member in lambda body
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1684 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
1685 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1686
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1687 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1688 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
1689
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1690 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
1691 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
1692 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
1693 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1694 Lam()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1695 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
1696 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1697 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1698
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1699 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
1700 assert_equal(13, foo.Add(7))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1701 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1702 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1703
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1704 # check shadowing
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1705 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
1706 vim9script
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 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1709 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
1710 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
1711 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
1712 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1713 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1714
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1715 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
1716 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
1717 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1718 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
1719
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
1720 # 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
1721 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
1722 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1723
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1724 class Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1725 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
1726 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
1727 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
1728 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
1729 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1730 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1731
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1732 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
1733 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
1734 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1735 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
1736
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1737 # 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
1738 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
1739 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
1740 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1741 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
1742 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
1743 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
1744 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
1745
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1746 # 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
1747 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1748 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1749 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1750 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
1751 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1752
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1753 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
1754 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
1755 obj.val = ""
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1756 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1757 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1758 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
1759 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
1760
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1761 # 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
1762 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1763 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1764 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1765 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
1766 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1767
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1768 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
1769 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
1770 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
1771 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1772 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1773 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
1774 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
1775
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1776 # 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
1777 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1778 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1779 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1780 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
1781 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1782
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1783 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1784 obj.val = ""
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1785 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
1786 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
1787
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1788 # 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
1789 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1790 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1791 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1792 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
1793 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1794
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1795 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1796 echo obj.val
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1797 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
1798 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
1799
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
1800 # 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
1801 # 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
1802 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
1803 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
1804 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1805 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
1806 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
1807 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
1808 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
1809 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
1810 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
1811 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1812 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
1813 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
1814 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
1815 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
1816
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1817 # 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
1818 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
1819 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
1820 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
1821 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
1822 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
1823 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
1824 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
1825 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
1826 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1827
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1828 " 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
1829 " 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
1830 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
1831 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
1832 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1833
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1834 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1835 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
1836 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1837
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1838 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
1839 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1840
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1841 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
1842 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
1843 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1844 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
1845 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1846 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1847
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1848 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1849 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
1850 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1851
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1852 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
1853 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1854
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1855 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1856 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
1857 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
1858 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1859 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1860 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1861 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
1862 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1863 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1864
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1865 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1866 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
1867 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1868
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1869 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
1870 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1871
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1872 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
1873 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1874 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1875 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
1876 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1877 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1878
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1879 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1880 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
1881 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1882
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1883 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
1884 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1885
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1886 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1887 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
1888 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1889 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1890 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1891 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1892
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1893 # 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
1894 # 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
1895 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
1896 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1897 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1898
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1899 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1900 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1901
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1902 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
1903 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
1904 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1905
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1906 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
1907 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1908
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1909 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1910 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
1911 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
1912 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1913 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1914 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1915 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
1916
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1917 # 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
1918 # 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
1919 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1920 vim9script
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 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1923 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1924
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1925 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
1926 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1927
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1928 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
1929 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
1930 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1931
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1932 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1933 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
1934 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
1935 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1936 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1937 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
1938 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
1939 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1940
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1941 func Test_class_garbagecollect()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1942 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
1943 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1944
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1945 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1946 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
1947 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
1948 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
1949 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1950
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1951 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
1952 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
1953 echo Point.pl Point.pd
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1954 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1955 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1956
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1957 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
1958 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1959
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1960 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
1961 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1962
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1963 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1964 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
1965 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1967 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
1968 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
1969
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1970 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
1971 # 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
1972 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
1973 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1974 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1975
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1976 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
1977
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1978 # 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
1979 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
1980 test_garbagecollect_now()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1981 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1982 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1983 endfunc
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1984
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1985 " Test interface garbage collection
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1986 func Test_interface_garbagecollect()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1987 let lines =<< trim END
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1988 vim9script
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1989
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1990 interface I
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
1991 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
1992
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1993 def ObjFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1994 endinterface
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1995
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1996 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
1997 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
1998 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
1999 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
2000 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
2001 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
2002
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2003 static def _ClassBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2004 return _priv_class_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2005 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2006
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2007 static def ClassFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2008 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
2009 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2010
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2011 def _ObjBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2012 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
2013 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2014
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2015 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
2016 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
2017 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2018 endclass
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2019
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2020 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
2021 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
2022 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
2023 test_garbagecollect_now()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2024 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
2025 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
2026 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2027 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
2028 endfunc
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
2029
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2030 def Test_class_method()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2031 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
2032 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2033 class Value
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2034 var value = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2035 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
2036
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2037 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
2038 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
2039 ++objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2040 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2041
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2042 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
2043 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
2044 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2045 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2046
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2047 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
2048 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
2049 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
2050 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
2051 assert_equal(2, Value.GetCount())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2052 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2053 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
2054
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2055 # 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
2056 # 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
2057 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
2058 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
2059 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
2060 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
2061 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
2062 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
2063 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
2064 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
2065 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
2066
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2067 # 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
2068 # name prefix.
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2069 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
2070 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2071 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2072 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
2073 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
2074 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
2075 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2076 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
2077 Foo(2)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2078 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2079 def Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2080 Foo(3)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2081 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2082 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2083 A.Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2084 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
2085 a.Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2086 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
2087 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2088 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2089 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2090
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2091 def Test_class_defcompile()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2092 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
2093 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2094
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2095 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
2096 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
2097 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
2098 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2099 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2100
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2101 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
2102 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2103 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
2104
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2105 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
2106 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2107
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2108 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
2109 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
2110 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
2111 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2112 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2113
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2114 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
2115 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2116 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
2117
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2118 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
2119 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2120
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2121 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
2122 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
2123 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2124 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2125
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2126 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
2127 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2128 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
2129
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
2130 # 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
2131 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
2132 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
2133 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
2134 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
2135 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
2136
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2137 # 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
2138 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
2139 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
2140 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
2141 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
2142 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
2143 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
2144
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2145 # 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
2146 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
2147 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
2148 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
2149 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
2150 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
2151 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
2152 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
2153
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2154 # 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
2155 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
2156 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
2157 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
2158 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
2159 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
2160 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
2161 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
2162 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
2163 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2164
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2165 def Test_class_object_to_string()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2166 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
2167 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2168 class TextPosition
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2169 var lnum = 1
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2170 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
2171 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2172
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2173 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
2174
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2175 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
2176 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
2177 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2178 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2179 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2180
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2181 def Test_interface_basics()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2182 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
2183 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2184 interface Something
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2185 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
2186 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
2187 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2188 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2189 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2190
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2191 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
2192 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2193 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
2194 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2195 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2196 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
2197
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2198 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
2199 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2200
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2201 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2202 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
2203 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
2204 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2205 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2206 # 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
2207 # 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
2208 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2209
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2210 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
2211 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2212 interface somethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2213 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
2214 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2215 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2216 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
2217
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2218 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
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 SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2221 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2222 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
2223 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
2224 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2225 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2226 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
2227
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2228 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
2229 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2230 interface SomethingWrong
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2231 var value: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2232 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
2233 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
2234 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
2235 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2236 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2237 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2238 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
2239
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2240 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
2241 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2242 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
2243 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
2244 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
2245 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2246 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2247 writefile(lines, 'XdefIntf.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2248
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2249 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
2250 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2251 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
2252 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
2253 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
2254 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2255 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2256 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2257 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
2258 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2259 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2260 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2261 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2262
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2263 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
2264 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2265 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
2266 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
2267 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2268 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
2269 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2270 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2271 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2272 writefile(imported, 'XdefIntf2.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2273
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2274 lines[1] = " import './XdefIntf2.vim' as defIntf"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2275 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2276 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2277
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2278 " 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
2279 def Test_interface_to_string()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2280 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2281 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2282 interface Intf
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2283 def Method(nr: number)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2284 endinterface
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2285 assert_equal("interface Intf", string(Intf))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2286 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2287 v9.CheckSourceSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2288 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
2289
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2290 def Test_class_implements_interface()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2291 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
2292 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2293
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2294 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2295 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
2296 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
2297 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2298
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2299 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
2300 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
2301 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
2302 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
2303 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2304 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2305
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2306 interface Another
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2307 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
2308 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2309
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2310 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
2311 var member = 'abc'
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2312 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
2313 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
2314 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
2315 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2316 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2317 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2318 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2319
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2320 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
2321 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2322
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2323 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2324 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
2325 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2326
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2327 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
2328 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
2329 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2330 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2331 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
2332
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2333 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
2334 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2335
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2336 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2337 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
2338 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2339
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2340 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
2341 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
2342 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2343 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2344 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
2345
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2346 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
2347 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2348
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2349 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2350 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
2351 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
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 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
2355 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
2356 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
2357 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
2358 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2359 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2360 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2361 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
2362
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2363 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
2364 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2365
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2366 interface Some
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2367 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
2368 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
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
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 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
2374 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
2375 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2376 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2377 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 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
2379
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2380 # Check different order of members in class and interface works.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2381 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
2382 vim9script
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2383
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2384 interface Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2385 var label: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2386 var errpos: number
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2387 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2388
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2389 # order of members is opposite of interface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2390 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
2391 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
2392 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
2393 var label: string = 'label'
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2394 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2395
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2396 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
2397 var result: Result = Failure.new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2398
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2399 assert_equal('label', result.label)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2400 assert_equal(42, result.errpos)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2401 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2402
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2403 Test()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2404 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2405 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
2406
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2407 # 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
2408 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
2409 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
2410 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
2411 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
2412 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
2413 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
2414 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
2415 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
2416
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2417 # 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
2418 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
2419 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
2420 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
2421 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
2422 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
2423 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
2424
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2425 # 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
2426 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
2427 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
2428 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
2429 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
2430 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
2431 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
2432
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2433 # 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
2434 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
2435 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
2436 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
2437 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
2438 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
2439 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
2440 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
2441 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
2442
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2443 # 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
2444 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
2445 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
2446 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
2447 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
2448 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
2449 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
2450 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
2451
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2452 # 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
2453 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2454 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2455 interface A
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2456 endinterface
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2457 class B implements A;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2458 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2459 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
2460 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
2461
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2462 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
2463 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2464
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2465 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
2466 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
2467 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2468 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
2469 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
2470 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2471 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2472 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2473 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
2474
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2475 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
2476 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2477
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2478 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
2479 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
2480 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2481 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
2482 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
2483 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2484 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2485 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2486 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
2487
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2488 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
2489 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2490
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2491 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
2492 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
2493 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2494 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
2495 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
2496 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2497 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2498 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2499 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
2500
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2501 # 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
2502 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2503 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2504
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2505 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2506 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2507 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2508 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2509
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2510 # 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
2511 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
2512 var mvar2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2513 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2514 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
2515 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
2516 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
2517 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
2518 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
2519 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
2520 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
2521 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2522 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2523
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2524 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
2525 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
2526 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
2527 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
2528 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2529 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2530
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2531 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
2532 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
2533 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
2534 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
2535 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2536 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2537
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2538 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
2539 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
2540 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2541
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2542 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2543 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2544 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2545
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2546 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
2547 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
2548 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
2549 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2550 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2551
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2552 # 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
2553 # 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
2554 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2555 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2556
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2557 interface I1
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2558 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2559 var mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2560 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2561
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2562 interface I2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2563 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2564 var mvar4: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2565 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2566
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2567 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
2568 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
2569 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
2570 var mvar1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2571 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
2572 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
2573 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
2574 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
2575 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
2576 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
2577 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2578 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2579
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2580 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
2581 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
2582 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
2583 var mvar3: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2584 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
2585 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
2586 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
2587 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
2588 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
2589 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
2590 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
2591 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
2592 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2593 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2594
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2595 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
2596 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
2597 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
2598 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
2599 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
2600 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
2601 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
2602 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
2603 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2604 endclass
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 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
2607 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
2608 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2609
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2610 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
2611 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
2612 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2613
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2614 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2615 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2616 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2617
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2618 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
2619 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
2620 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
2621 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2622 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
2623
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2624 # 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
2625 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
2626 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2627 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2628 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2629 interface B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2630 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2631 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
2632 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2633 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2634 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
2635
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2636 # 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
2637 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
2638 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2639 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2640 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2641 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
2642 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2643 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2644 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
2645
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2646 # 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
2647 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
2648 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2649 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
2650 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2651 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2652 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2653 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2654
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2655 def Test_call_interface_method()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2656 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2657 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2658 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2659 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2660 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2661
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2662 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2663 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2664 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2665 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2666 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2667
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2668 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2669 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2670 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2671
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2672 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2673 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2674 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2675 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2676 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2677 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2678
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2679 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2680 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2681 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2682 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2683 g:result ..= 'base'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2684 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2685 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2686
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2687 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2688 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2689 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2690 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2691 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2692
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2693 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2694 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2695 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2696
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2697 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2698 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2699 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2700 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2701 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2702 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2703
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2704 # method of interface returns a value
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2705 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2706 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2707 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2708 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2709 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2710
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2711 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2712 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2713 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2714 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2715 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2716 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2717
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2718 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2719 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2720 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2721 enddef
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 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2724 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2725 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2726 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2727 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2728 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2729
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2730 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2731 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2732 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2733 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2734 return null_string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2735 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2736 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2737
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2738 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2739 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2740 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2741 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2742 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2743 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2744
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2745 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2746 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2747 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2748 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2749
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2750 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2751 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2752 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2753 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2754 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2755 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2756
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2757 # No class that implements the interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2758 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
2759 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2760
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2761 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
2762 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
2763 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
2764 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2765
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2766 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
2767 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
2768 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2769
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2770 defcompile
32670
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 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2774
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2775 def Test_class_used_as_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2776 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
2777 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2778
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2779 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2780 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2781 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
2782 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2783
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2784 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
2785 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
2786 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
2787 assert_equal(33, p.y)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2788 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2789 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2790
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2791 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
2792 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2793
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2794 interface HasX
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2795 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
2796 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2797
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2798 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
2799 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2800 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
2801 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2802
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2803 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
2804 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
2805 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
2806 assert_equal(2, hx.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2807 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2808 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2809
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2810 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
2811 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2812
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2813 class Point
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2814 var x = 0
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2815 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
2816 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2817
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2818 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
2819 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
2820 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2821 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
2822 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2823
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2824 def Test_class_extends()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2825 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
2826 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2827 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2828 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
2829 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
2830 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
2831 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2832 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2833 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
2834 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
2835 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
2836 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
2837 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2838 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2839 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
2840 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
2841 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
2842 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
2843 assert_equal(3, o.GetTotal())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2844 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2845 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2846
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2847 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
2848 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2849 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2850 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
2851 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2852 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
2853 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
2854 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2855 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
2856 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
2857 assert_equal(44, o.two)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2858 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2859 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2860
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2861 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
2862 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2863 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2864 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
2865 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2866 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
2867 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
2868 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2869 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2870 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
2871
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2872 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
2873 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2874 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
2875 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
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 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2878 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
2879
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2880 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
2881 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2882 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
2883 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
2884 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
2885 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2886 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2887 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
2888
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2889 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
2890 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2891 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2892 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
2893 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
2894 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
2895 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2896 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2897
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2898 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
2899 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
2900 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
2901 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
2902 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2903 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2904
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2905 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
2906 assert_equal('John: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2907 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2908 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2909
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2910 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
2911 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2912 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2913 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
2914 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
2915 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
2916 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2917 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
2918 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
2919 enddef
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, '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
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 class Child
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2927 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
2928 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
2929 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
2930 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2931 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2932 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
2933 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
2934 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2935 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
2936
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2937 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
2938 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2939 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2940 var name: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2941 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
2942 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
2943 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2944 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2945
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2946 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
2947 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
2948 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
2949 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2950 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
2951 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2952 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
2953
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2954 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
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(): string
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 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
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 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2962 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
2963 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
2964 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2965 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
2966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2967 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
2968 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2969 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2970 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
2971 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
2972 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
2973 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2974 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2975
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2976 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
2977 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
2978 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
2979 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
2980 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2981 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2982
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2983 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
2984 assert_equal('Base class: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2985 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2986 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2987
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2988 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
2989 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2990 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
2991 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
2992 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
2993 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
2994 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2995 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2996 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
2997 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
2998 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
2999 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3000 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3001 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
3002 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3003 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
3004
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3005 # base class with more than one object member
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3006 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
3007 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3008
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3009 class Result
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3010 var success: bool
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3011 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
3012 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3013
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3014 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
3015 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
3016 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
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 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
3021 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
3022 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3023 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
3024
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3025 # 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
3026 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
3027 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
3028 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
3029 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
3030 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
3031 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
3032 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 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
3034 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3035
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3036 def Test_using_base_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3037 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3038 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3039
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3040 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
3041 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
3042 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
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 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
3045 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3046 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3047
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3048 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
3049 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
3050 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
3051 enddef
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 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
3054 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
3055 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3056 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3057
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3058 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
3059 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
3060 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3061 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
3062 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3063 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
3064 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
3065 endtry
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3066 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3067
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3068 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3069 With(ChildEE.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3070 assert_equal('42/finally/exit', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3071 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3072 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3073 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3074
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3075 # 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
3076 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3077 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3078
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3079 class Base
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3080 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
3081 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
3082 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
3083 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3084 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3085
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3086 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
3087 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
3088 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
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 var obj = Child.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3093 assert_equal(true, obj.success)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3094 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3095 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3096 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3097
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3098 def Test_class_import()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3099 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
3100 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3101 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
3102 var kind: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3103 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
3104 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3105 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3106 writefile(lines, 'Xanimal.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3107
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3108 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
3109 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3110 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
3111
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3112 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
3113 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
3114 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
3115 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
3116
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3117 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
3118 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
3119 assert_equal('Garfield', b.name)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3120 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3121 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3122 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3123
34759
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3124 " 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
3125 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
3126 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
3127 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3128 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
3129 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
3130 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
3131 name = n
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3132 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3133 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3134 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3135 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
3136
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3137 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
3138 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
3139
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3140 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
3141 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
3142 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3143 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
3144 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3145
33929
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3146 " 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
3147 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
3148 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
3149 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3150 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
3151 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
3152 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3153 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
3154 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
3155 endinterface
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3156 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3157 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
3158
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3159 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
3160 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3161 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
3162
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3163 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
3164 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
3165 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
3166 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3167 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
3168 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
3169 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3170 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3171 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
3172 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
3173 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
3174 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3175 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
3176 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3177
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3178 " 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
3179 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
3180 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
3181 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3182 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
3183 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
3184 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
3185 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3186 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3187 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3188 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
3189
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3190 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
3191 vim9script
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3192 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
3193
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3194 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
3195 endclass
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3196 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
3197 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
3198 END
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3199 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
3200 enddef
34c5f47e98ba patch 9.0.2161: Vim9: not able to use imported interfaces and classes
Christian Brabandt <cb@256bit.org>
parents: 33924
diff changeset
3201
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3202 def Test_abstract_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3203 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
3204 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3205 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
3206 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
3207 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3208 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
3209 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
3210 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3211 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
3212 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
3213 assert_equal(42, p.age)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3214 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3215 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3216
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3217 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
3218 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3219 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
3220 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
3221 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3222 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
3223 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
3224 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3225 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
3226 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
3227 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
3228
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3229 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
3230 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
3231 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
3232 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3233 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3234 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
3235
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3236 # 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
3237 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
3238 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
3239 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
3240 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
3241 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
3242 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
3243 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
3244 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
3245
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3246 # 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
3247 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
3248 vim9script
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3249 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
3250 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
3251 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
3252 return [10]
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3253 enddef
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3254 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3255 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
3256 endclass
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3257 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
3258 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
3259 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
3260 END
a14868d39709 patch 9.1.0257: Vim9: :call may not find imported class members
Christian Brabandt <cb@256bit.org>
parents: 34755
diff changeset
3261 v9.CheckScriptSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3262 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3263
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3264 def Test_closure_in_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3265 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
3266 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3267
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3268 class Foo
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3269 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
3270
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3271 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
3272 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
3273 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3274 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3275
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3276 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
3277 assert_equal(['A'], g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3278 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3279 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3280 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3281
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3282 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
3283 # Cannot directly invoke constructor from legacy
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3284 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
3285 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3286
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3287 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3288
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3289 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3290 def new(arg: string)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3291 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3292 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3293 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3294
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3295 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
3296 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
3297 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3298
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3299 g:P = CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3300 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
3301 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3302 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3303 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3304 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3305
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3306 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3307 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3308
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3309 var newCalled = false
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3310
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3311 class A
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3312 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
3313 return A.new()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3314 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
3315 def new()
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3316 newCalled = true
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3317 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3318 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3319
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3320 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3321 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3322 assert_equal(true, newCalled)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3323 unlet g:P
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3324 END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3325 v9.CheckSourceSuccess(lines)
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3326
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3327 # 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
3328 lines =<< trim END
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3329 vim9script
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3330
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3331 var createdObject: any
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3332
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3333 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3334 var val1: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3335 var val2: number
33913
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3336 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
3337 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
3338 return createdObject
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3339 enddef
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3340 endclass
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3341
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3342 g:P = A.CreateA
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3343 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
3344 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
3345 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
3346 legacy call g:P()
a259471e74fe patch 9.0.2156: Vim9: can use typealias in assignment
Christian Brabandt <cb@256bit.org>
parents: 33886
diff changeset
3347 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
3348 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
3349 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
3350 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
3351 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
3352 unlet g:P
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3353 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3354 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3355 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3356
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3357 def Test_defer_with_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3358 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
3359 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3360
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3361 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
3362 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
3363 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
3364 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3365 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
3366 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
3367 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3368 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3369
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3370 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
3371 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
3372 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
3373 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3374 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3375
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3376 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
3377 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
3378 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
3379 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
3380 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3381 assert_equal('entered/called/exited', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3382 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3383 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3384 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3385
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3386 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
3387 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3388
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3389 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
3390 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
3391 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
3392 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3393 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
3394 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
3395 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3396 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3397
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3398 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
3399 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
3400 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
3401 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3402 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
3403 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
3404 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3405 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3406
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3407 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
3408 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
3409 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
3410 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3411 enddef
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 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
3414 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
3415 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
3416 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
3417 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3418 assert_equal('entered-child/called/exited-child', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3419 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3420 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3421 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3422 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3423
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3424 " 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
3425 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
3426 var lines =<< trim END
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3427 vim9script
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3428
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3429 class Observer
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3430 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3431
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3432 class Property
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3433 var value: any
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3434
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3435 def Set(v: any)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3436 if v != this.value
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3437 this.value = v
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3438 endif
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3439 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3440
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3441 def Register(observer: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3442 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3443 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3444
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3445 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
3446 var value2: bool
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3447 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3448
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3449 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
3450 obj.Register(who)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3451 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3452
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3453 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
3454 var myObserver = Observer.new()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3455
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3456 Observe(p, myObserver)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3457
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3458 p.Set(true)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3459 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3460 v9.CheckSourceSuccess(lines)
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3461 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3462
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3463 " 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
3464 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
3465 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
3466 vim9script
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3467
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3468 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
3469 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
3470
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3471 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
3472 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
3473 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
3474 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3475
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3476 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
3477 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
3478 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3479 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3480
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3481 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
3482 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3483
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3484 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
3485 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
3486 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3487
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3488 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
3489 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
3490
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3491 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
3492 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
3493 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
3494 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3495 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
3496 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3497
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3498 def Test_instanceof()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3499 var lines =<< trim END
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3500 vim9script
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3501
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3502 class Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3503 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3504
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3505 class Base2 extends Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3506 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3507
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3508 interface Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3509 endinterface
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3510
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3511 class Mix1 implements Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3512 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3513
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3514 class Base3 extends Mix1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3515 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3516
33924
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3517 type AliasBase1 = Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3518 type AliasBase2 = Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3519 type AliasIntf1 = Intf1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3520 type AliasMix1 = Mix1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3521
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3522 var b1 = Base1.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3523 var b2 = Base2.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3524 var b3 = Base3.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3525
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3526 assert_true(instanceof(b1, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3527 assert_true(instanceof(b2, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3528 assert_false(instanceof(b1, Base2))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3529 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
3530 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
3531
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3532 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
3533 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
3534 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
3535 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
3536 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
3537
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3538 def Foo()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3539 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
3540 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
3541 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
3542
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3543 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
3544 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
3545 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
3546 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
3547 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
3548
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3549 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
3550 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
3551 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
3552 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
3553 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
3554 enddef
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3555 Foo()
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3556
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3557 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
3558 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
3559
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3560 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3561 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
3562
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3563 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3564 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3565
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3566 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3567 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3568 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3569 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3570 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
3571
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3572 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3573 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3574
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3575 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3576 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3577 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3578 instanceof(Base1.new())
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3579 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3580 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3581 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3582 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
3583
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3584 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3585 vim9script
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3586
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3587 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3588 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3589
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3590 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3591 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3592
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3593 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
3594 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
3595 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3596 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
3597
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3598 lines =<< trim END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3599 vim9script
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 class Base1
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3602 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3603
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3604 class Base2
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3605 endclass
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3606
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3607 def F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3608 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
3609 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
3610 enddef
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3611 F()
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3612 END
ccdb948c7273 patch 9.0.2160: instanceof() should use varargs as second arg
Christian Brabandt <cb@256bit.org>
parents: 33913
diff changeset
3613 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
3614 enddef
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3615
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3616 " 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
3617 " 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
3618 " 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
3619 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
3620 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
3621 vim9script
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3622
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3623 class Widget
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3624 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
3625
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3626 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
3627 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
3628 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3629
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3630 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
3631 return ''
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3632 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3633 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3634
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3635 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
3636 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
3637 return '<Foo>'
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3638 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3639 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3640
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3641 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
3642 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
3643 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
3644 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
3645 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3646
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3647 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
3648 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
3649 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
3650 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3651 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
3652 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3653
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
3654 " 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
3655 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
3656 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
3657 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
3658
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3659 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
3660 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
3661 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
3662 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
3663 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
3664 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
3665
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3666 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
3667 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
3668 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
3669 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
3670
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3671 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
3672 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
3673 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
3674
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3675 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
3676 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
3677 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
3678 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
3679
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3680 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
3681 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
3682 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
3683 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
3684
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3685 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
3686 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
3687 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
3688 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
3689
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3690 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
3691 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
3692 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
3693 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
3694 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
3695
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3696 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
3697 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
3698 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
3699 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
3700 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
3701
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3702 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
3703 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
3704 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
3705 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
3706 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
3707
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 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
3709 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
3710 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
3711 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
3712 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
3713
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 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
3715 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
3716 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
3717 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
3718 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
3719 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
3720 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
3721 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
3722 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
3723 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
3724 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3725 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
3726 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
3727
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 " 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
3729 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
3730 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
3731 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
3732
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 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3734 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
3735 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
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 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
3738 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
3739 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
3740
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 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
3742 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
3743 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
3744
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 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
3746 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
3747 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
3748
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 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
3750 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
3751 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
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 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
3755 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
3756 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
3757 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
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 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
3761 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
3762 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
3763 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
3764 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
3765 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
3766 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
3767 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3768 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
3769 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
3770
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3771 " 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
3772 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
3773 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
3774 vim9script
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3775
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3776 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
3777 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
3778 F0()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3779 enddef
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3780 endclass
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3781
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3782 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
3783 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
3784 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3785
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3786 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
3787 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
3788 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3789
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3790 F()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3791 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3792 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
3793 enddef
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3794
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3795 " 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
3796 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
3797 # 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
3798 var lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3799 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3800
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3801 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3802 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3803
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3804 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3805 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3806 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3807 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3808 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3809 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3810
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3811 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
3812 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
3813
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3814 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3815 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3816 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
3817
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3818 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3819 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3820 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3821 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
3822 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3823 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3824 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3825 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3826
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3827 # 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
3828 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3829 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3830
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3831 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3832 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3833
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3834 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3835 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3836 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3837 return
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3838 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3839 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3840 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3841
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3842 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
3843 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
3844
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3845 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3846 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3847 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
3848
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3849 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3850 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3851 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3852 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
3853 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3854 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3855 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3856 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3857
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3858 # 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
3859 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3860 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3861
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3862 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3863 var _bufnr: number
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3864
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3865 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
3866 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3867 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3868 return this
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3869 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3870 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3871 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3872 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
3873 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
3874
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3875 # 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
3876 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3877 vim9script
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 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3880 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
3881
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3882 def new(): dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3883 this._state = {}
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3884 return this._state
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3885 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3886 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3887
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3888 var c = C.new()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3889 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
3890 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
3891 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
3892 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3893
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3894 " 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
3895 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
3896 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
3897 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3898
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3899 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
3900
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3901 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
3902 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
3903 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
3904 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
3905 else
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3906 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
3907 endif
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3908 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3909
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3910 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3911 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
3912 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3913
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3914 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
3915 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
3916 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
3917 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
3918 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3919
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3920 " 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
3921 " object.
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3922 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
3923 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
3924 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3925
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3926 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3927 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
3928 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
3929 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3930 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3931
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3932 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
3933 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
3934
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3935 var current: C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3936 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
3937 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
3938 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
3939 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
3940
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3941 def F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3942 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
3943 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3944
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3945 def G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3946 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
3947 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3948
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3949 F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3950 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
3951 G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3952 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
3953 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3954 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
3955 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3956
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3957 " 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
3958 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
3959 # 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
3960 # 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
3961 # 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
3962 # Also different depths
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3963
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3964 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3965 # 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
3966 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3967
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3968 # 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
3969 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3970 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3971
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3972 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3973 var val1: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3974 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3975 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3976 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3977 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3978 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
3979 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3980 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
3981 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
3982
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3983 # 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
3984 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3985 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3986
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3987 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
3988 var val2: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3989 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3990 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
3991 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3992 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3993 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
3994
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3995 # 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
3996 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3997 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3998
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3999 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4000 var val3: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4001 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4002 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
4003 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4004 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4005 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4006 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4007 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4008 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
4009
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4010 # 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
4011 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4012 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4013
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4014 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4015 var val4: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4016 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4017 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4018 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4019 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4020 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4021 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4022 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
4023
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4024 # 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
4025 # 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
4026
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4027 # 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
4028 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4029 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4030
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4031 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4032 var val5: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4033 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
4034 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4035 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4036 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4037 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
4038 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
4039 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4040 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
4041
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4042 # 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
4043 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4044 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4045
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4046 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4047 var val6: number
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4048 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
4049 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4050 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4051 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4052 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
4053 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4054 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4055 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
4056
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4057 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4058 # 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
4059 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4060
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4061 # lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4062 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4063 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4064
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4065 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4066 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
4067 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4068 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4069 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4070 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4071 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
4072 o.Lock()
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, '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
4075
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4076 # lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4077 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4078 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4079
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4080 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4081 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
4082 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4083 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
4084 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4085 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4086 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
4087
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4088 # 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
4089 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4090 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4091
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4092 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4093 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
4094 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4095 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
4096 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4097 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4098 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4099 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4100 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4101 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
4102
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4103 # 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
4104 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4105 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4106
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4107 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4108 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
4109 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4110 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4111 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4112 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4113 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4114 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4115 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
4116
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4117 # 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
4118 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4119 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4120
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4121 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4122 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
4123 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
4124 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4125 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4126 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4127 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
4128 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
4129 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4130 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
4131
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4132 # 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
4133 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4134 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4135
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4136 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4137 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
4138 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
4139 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4140 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4141 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4142 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
4143 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4144 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4145 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
4146 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4147
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4148 " 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
4149 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
4150
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4151 # 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
4152 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4153 vim9script
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 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4156 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
4157 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4158 lockvar sval1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4159 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4160 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4161 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4162 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4163 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4164 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
4165
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4166 # 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
4167 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4168 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4169
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4170 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4171 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
4172 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4173 lockvar C.sval2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4174 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4175 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4176 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4177 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4178 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4179 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
4180
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4181 # 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
4182 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4183 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4184
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4185 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4186 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
4187 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4188 lockvar sval3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4189 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4190 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4191 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4192 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4193 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
4194
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4195 # 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
4196 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4197 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4198
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4199 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4200 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
4201 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4202 lockvar C.sval4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4203 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4204 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4205 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4206 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4207 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
4208
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4209 # 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
4210 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4211 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4212
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4213 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4214 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
4215 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4216 lockvar C.sval5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4217 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4218 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
4219
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4220 # 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
4221 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4222 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4223
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4224 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4225 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
4226 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4227 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4228 lockvar o.sval6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4229 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4230 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
4231 enddef
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 " 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
4234 def Test_lockvar_argument()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4235 # Lockvar a function arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4236 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4237 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4238
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4239 def Lock(val: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4240 lockvar val
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
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4243 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
4244 Lock(d)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4245
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4246 d->extend({c: 3})
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4247 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4248 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
4249
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4250 # 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
4251 # 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
4252 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4253 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4254
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4255 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4256 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
4257 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4258
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4259 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4260 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4261 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4262
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4263 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4264 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4265 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4266 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4267
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4268 # Lock a class.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4269 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4270 vim9script
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 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4273 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
4274 endclass
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 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4277 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4278 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4279
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4280 Lock2(C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4281 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
4282 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
4283
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4284 # Lock an object.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4285 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4286 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4287
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4288 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4289 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
4290 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4291
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4292 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4293 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4294 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4295
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4296 Lock2(C.new())
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4297 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4298 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4299
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4300 # 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
4301 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4302 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4303
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4304 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4305 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
4306 def Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4307 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4308 enddef
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
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4312 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4313 o.Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4314 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4315 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
4316 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4317
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4318 " 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
4319 def Test_lockvar_this()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4320 # lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4321 var 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 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4324 def TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4325 lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4326 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4327 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4328 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4329 o.TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4330 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4331 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4332
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4333 # 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
4334 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4335 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4336 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4337 def TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4338 var four: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4339 lockvar four
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4340 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4341 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4342 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4343 o.TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4344 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4345 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
4346
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4347 # 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
4348 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4349 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4350 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4351 def TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4352 var this5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4353 lockvar this5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4354 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4355 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4356 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4357 o.TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4358 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4359 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
4360 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4361
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4362 " 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
4363 def Test_lockvar_general()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4364 # 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
4365 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4366 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4367 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4368 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4369 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4370 lockvar o
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4371 lockvar C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4372 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4373 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4374
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4375 # 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
4376 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4377 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4378
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4379 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4380 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
4381 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4382 def Lock2(obj: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4383 lockvar obj.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4384 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4385
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4386 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4387 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4388 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4389 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
4390 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4391 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4392 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
4393 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4394 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4395 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4396 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4397 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
4398 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4399 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4400
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4401 # 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
4402 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4403 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4404
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4405 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4406 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
4407 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4408
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4409 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4410 lockvar o.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4411 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4412 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
4413 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4414 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4415 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
4416 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4417 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4418 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4419 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4420 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
4421 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4422 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
4423
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4424 # 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
4425 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4426 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4427
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4428 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4429 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4430 lockvar l
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4431 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4432 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4433
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4434 var l = [1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4435 C.new().Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4436 l[0] = 11
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4437 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4438 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
4439
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4440 # 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
4441 # 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
4442 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4443 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4444
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4445 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4446 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
4447 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4448 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
4449 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4450 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4451
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4452 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
4453 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
4454 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
4455
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4456 o.Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4457 l[0] = [22]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4458 l[1] = [33]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4459 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4460 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
4461
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4462 # 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
4463 # 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
4464 # 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
4465 # the same name.
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4466 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4467 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4468
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4469 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4470 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
4471 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
4472 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
4473 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4474 endclass
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 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4477 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
4478 endclass
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 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
4481 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
4482 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
4483
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4484 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
4485 o2.Lock(o)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4486 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4487 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
4488 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4489
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4490 " Test builtin islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4491 def Test_lockvar_islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4492 # Can't lock class/object variable
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4493 # 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
4494 # 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
4495 # 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
4496 var lines =<< trim END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4497 vim9script
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4498
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4499 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4500 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
4501 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
4502 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
4503 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
4504 endclass
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4505
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4506 def LockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4507 lockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4508 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4509
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4510 def UnlockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4511 unlockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4512 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4513
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4514 var obj = C.new()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4515 #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
4516
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4517 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4518 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
4519 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
4520 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4521 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4522 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4523
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4524 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
4525 assert_equal(1, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4526 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
4527 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
4528 UnlockIt(obj.o1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4529 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4530 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
4531
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4532 lockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4533 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4534 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
4535 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
4536 unlockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4537 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4538 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
4539
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4540 # Same thing, but with a static
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4541
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4542 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4543 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
4544 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
4545 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4546 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4547 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4548
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4549 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
4550 assert_equal(1, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4551 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
4552 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
4553 UnlockIt(C.c1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4554 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4555 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
4556
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4557 lockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4558 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4559 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
4560 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
4561 unlockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4562 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4563 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
4564 END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4565 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
4566
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4567 # 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
4568 # 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
4569 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
4570 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4571
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4572 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
4573 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
4574 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
4575 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
4576
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4577 class C0
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4578 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
4579 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
4580 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
4581 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
4582 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
4583 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
4584 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4585 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
4586 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
4587 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4588 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4589
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4590 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
4591 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
4592 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
4593 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
4594
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4595 class C2
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4596 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
4597 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
4598 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
4599 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
4600 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
4601 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
4602 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4603 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
4604 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
4605 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4606 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4607
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4608 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
4609 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
4610
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4611 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
4612
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4613 # 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
4614 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
4615 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
4616 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
4617 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
4618 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
4619
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4620 #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
4621
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4622 # 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
4623 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
4624 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
4625 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
4626
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4627 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
4628 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
4629 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
4630 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
4631
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4632 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
4633
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4634 # 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
4635 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
4636 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
4637 # 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
4638 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
4639 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
4640
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4641 # 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
4642 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
4643 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
4644 # 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
4645 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
4646 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
4647
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4648
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4649 # 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
4650 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
4651 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
4652 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
4653
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4654 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4655 # 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
4656 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4657
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4658 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
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 # 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
4661 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
4662 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
4663 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
4664 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
4665 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
4666
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4667 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
4668
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4669 # 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
4670 try
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4671 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
4672 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
4673 catch
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4674 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
4675 endtry
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4676
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4677 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
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 # 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
4680 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
4681 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
4682 # 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
4683 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
4684 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
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 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
4687 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
4688 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
4689 # 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
4690 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
4691 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
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
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4694 # 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
4695 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
4696 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
4697 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
4698 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
4699 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4700 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
4701
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4702 # 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
4703 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
4704 vim9script
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 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
4707 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
4708 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
4709 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4710 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
4711 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
4712 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4713 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4714 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
4715
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4716 # 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
4717 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
4718 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
4719
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4720 # 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
4721 ### 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
4722 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
4723
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4724 #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
4725 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
4726 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
4727 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
4728 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
4729 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
4730 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4731 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
4732 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4733
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4734 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
4735 # 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
4736 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
4737 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4738
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4739 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
4740 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
4741 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
4742 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4743 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
4744 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
4745 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4746 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4747 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
4748 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
4749 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
4750 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4751 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
4752
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4753 # 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
4754 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
4755 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4756
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4757 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
4758 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4759 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
4760
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4761 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
4762 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4763
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4764 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
4765 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
4766 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
4767 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
4768 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4769 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4770 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
4771 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
4772 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4773 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
4774
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4775 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
4776 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4777
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4778 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
4779 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
4780 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
4781 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4782 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4783 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
4784 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
4785 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
4786 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
4787
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4788 # 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
4789 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
4790 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4791
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4792 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
4793 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
4794 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
4795 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
4796 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4797 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
4798 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
4799 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4800 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4801 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
4802 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
4803 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
4804 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
4805 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
4806 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
4807 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4808 v9.CheckSourceSuccess(lines)
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4809 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4810
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4811 " 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
4812 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
4813 # 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
4814 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
4815 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4816
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4817 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4818 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4819 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4820 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4821 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4822 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
4823 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4824 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4825 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
4826
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4827 # 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
4828 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4829 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4830
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4831 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4832 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4833 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4834 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4835 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4836 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4837 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
4838 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4839 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4840 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4841 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4842 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
4843
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4844 # 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
4845 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4846 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4847
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4848 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4849 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4850 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4851 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4852 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4853 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4854 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4855 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4856 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
4857 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
4858 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4859 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
4860
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4861 # 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
4862 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4863 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4864
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4865 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4866 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4867 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4868 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4869 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4870 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4871 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4872 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4873 def T()
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 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
4876 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4877 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4878 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4879 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
4880
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4881 # 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
4882 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4883 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4884
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4885 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4886 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4887 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4888 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4889 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4890 return _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 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4893 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
4894 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4895 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
4896 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
4897
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4898 # 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
4899 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4900 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4901
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4902 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4903 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4904 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4905 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4906 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4907 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4908 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4909 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
4910
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4911 # 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
4912 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4913 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4914
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4915 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4916 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4917 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4918 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4919 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4920 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4921 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
4922 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
4923 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
4924
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4925 # 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
4926 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4927 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4928
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4929 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4930 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4931 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4932 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4933 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4934 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4935 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
4936 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
4937 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
4938
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4939 # 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
4940 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4941 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4942
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4943 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4944 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4945 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4946 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4947 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4948 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4949 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
4950 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
4951 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
4952
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4953 # 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
4954 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4955 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4956
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4957 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4958 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4959 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4960 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4961 def _Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4962 return 200
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4963 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4964 def _Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4965 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
4966 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
4967 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4968 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4969 this._Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4970 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4971 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4972 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
4973 a.T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4974 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4975 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
4976
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4977 # 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
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(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4983 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4984 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4985 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4986 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4987 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4988 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
4989 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4990 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4991 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4992 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
4993 b.Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4994 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4995 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
4996
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
4997 # 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
4998 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4999 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5000 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5001 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5002 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5003 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5004 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5005 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
5006 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5007 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5008 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5009 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
5010 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5011 return this._Foo()
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 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5014 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
5015 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
5016 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5017 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
5018
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5019 # 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
5020 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5021 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5022 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5023 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5024 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5025 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5026 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5027 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
5028 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5029 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5030 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5031 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
5032 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5033 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5034 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5035 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
5036 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
5037 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5038 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
5039
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5040 # 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
5041 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5042 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5043 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5044 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5045 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5046 var a = _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5047 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
5048 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
5049 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5050
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5051 " 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
5052 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
5053 # 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
5054 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
5055 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5056
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5057 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5058 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
5059 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5060 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5061 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5062 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5063 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5064 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
5065
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5066 # 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
5067 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5068 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5069
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5070 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5071 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
5072 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5073 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5074 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5075 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5076 A._Foo()
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 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5079 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5080 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
5081
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5082 # 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
5083 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5084 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5085
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5086 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5087 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
5088 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5089 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5090 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5091 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
5092 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5093 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5094 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
5095
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5096 # 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
5097 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5098 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5099
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5100 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5101 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
5102 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5103 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5104 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5105 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5106 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
5107 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5108 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5109 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5110 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5111 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
5112
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5113 # 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
5114 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5115 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5116
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5117 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5118 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
5119 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5120 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5121 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
5122 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
5123 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5124 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5125 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
5126 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5127 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5128 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
5129
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5130 # 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
5131 # 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
5132 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5133 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5134
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5135 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5136 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
5137 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5138 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5139 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
5140 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
5141 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5142 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
5143 _Foo2()
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5144 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5145 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5146 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
5147 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5148 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5149 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
5150
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5151 # 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
5152 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5153 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5154
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5155 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5156 static def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5157 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5158 static def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5159 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5160 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5161 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
5162 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
5163 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
5164
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5165 # 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
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 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5174 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5175 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5176 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5177 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5178 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5179 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
5180 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
5181 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5182 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
5183
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5184 # 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
5185 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5186 vim9script
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 _Foo(): 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 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5192 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
5193 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5194 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5195 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5196 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
5197 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5198 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5199 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5200 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5201 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
5202 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
5203 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5204 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
5205
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5206 # 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
5207 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5208 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5209 class A
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(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5211 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5212 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5213 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5214 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
5215 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5216 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5217 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5218 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
5219 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
5220 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5221 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5222 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5223 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
5224 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5225 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
5226
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5227 # 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
5228 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5229 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5230 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5231 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
5232 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5233 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5234 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5235 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
5236 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5237 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5238 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5239 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
5240 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5241 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5242 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5243 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
5244 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
5245 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5246 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
5247 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
5248
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5249 " 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
5250 " argument.
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5251 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
5252 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
5253 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5254
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5255 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
5256 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
5257 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
5258 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5259 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5260
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5261 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
5262 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
5263 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5264
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5265 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
5266 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
5267 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5268
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5269 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
5270 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
5271 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5272 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
5273
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5274 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
5275 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5276
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5277 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
5278 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
5279 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
5280 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5281 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5282
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5283 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
5284 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
5285 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5286
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5287 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
5288 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
5289 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5290
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5291 Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5292 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5293 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
5294 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
5295
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5296 def Test_static_inheritence()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5297 # 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
5298 var lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5299 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5300
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5301 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5302 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
5303 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
5304 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
5305 _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
5306 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
5307 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5308 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
5309 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
5310 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5311 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
5312 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
5313 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5314 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5315
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5316 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
5317 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
5318 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
5319 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5320 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5321
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5322 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
5323 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
5324 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
5325 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5326
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5327 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
5328 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
5329 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
5330 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5331 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5332
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5333 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5334 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5335 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5336 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
5337 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
5338 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
5339
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5340 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
5341
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5342 # 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
5343 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
5344 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
5345 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
5346 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5347 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5348 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5349
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5350 " 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
5351 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
5352 # 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
5353 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
5354 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5355 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5356 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5357 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
5358 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5359 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
5360 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
5361
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5362 # 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
5363 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
5364 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5365 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5366 var _val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5367 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
5368 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5369 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
5370 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
5371
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5372 # 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
5373 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
5374 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5375 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5376 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
5377 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
5378 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5379 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
5380 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
5381
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5382 # 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
5383 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
5384 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5385 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5386 var val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5387 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
5388 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5389 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
5390 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
5391
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5392 # 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
5393 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
5394 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5395 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5396 var _val = 20
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5397 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
5398 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5399 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
5400 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
5401
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5402 # 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
5403 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
5404 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5405 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5406 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
5407 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
5408 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5409 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
5410 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
5411
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5412 # 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
5413 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
5414 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5415 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5416 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
5417 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
5418 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5419 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
5420 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
5421
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5422 # 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
5423 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
5424 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5425 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5426 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
5427 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
5428 def new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5429 enddef
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 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
5432 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
5433 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
5434 END
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
5435 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
5436
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5437 # 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
5438 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
5439 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5440 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5441 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
5442 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5443 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
5444 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5445 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
5446 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
5447 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5448 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
5449 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
5450
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5451 # 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
5452 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
5453 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5454 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5455 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
5456 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5457 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
5458 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5459 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
5460 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
5461 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5462 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
5463 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
5464
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5465 # 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
5466 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
5467 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5468 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5469 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
5470 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5471 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
5472 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5473 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
5474 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
5475 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5476 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
5477 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
5478
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5479 # 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
5480 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
5481 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5482 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5483 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
5484 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5485 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
5486 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5487 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
5488 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
5489 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5490 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
5491 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
5492
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5493 # 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
5494 lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5495 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5496 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5497 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
5498 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
5499 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5500 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5501 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
5502 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5503
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5504 " 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
5505 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
5506 # 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
5507 var lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5508 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5509 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5510 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5511 def GetVal(): number
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5512 return this._val
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5513 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5514 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5515 def T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5516 var a = A.new()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5517 a._val = 20
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5518 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5519 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5520 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5521 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
5522
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5523 # 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
5524 lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5525 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5526 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5527 var _val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5528 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5529 def T()
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5530 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
5531 a._a = 1
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5532 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5533 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5534 END
33627
41c64cb748c1 patch 9.0.2055: Vim9: non-consistent error messages
Christian Brabandt <cb@256bit.org>
parents: 33618
diff changeset
5535 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
5536
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5537 # 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
5538 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5539 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5540 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5541 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
5542 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5543 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5544 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5545 var x = a._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5546 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5547 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5548 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
5549 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
5550
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5551 # 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
5552 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5553 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5554 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5555 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
5556 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5557 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5558 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5559 a._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5560 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5561 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5562 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
5563 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
5564
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5565 # 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
5566 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5567 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5568 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5569 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
5570 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5571 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5572 var x = A._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5573 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5574 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5575 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5576 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
5577
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5578 # 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
5579 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5580 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5581 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5582 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
5583 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5584 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5585 A._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5586 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5587 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5588 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
5589 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
5590 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5591
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5592 " 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
5593 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
5594 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
5595 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5596 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5597 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
5598 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5599 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
5600 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
5601 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5602 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
5603 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
5604
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5605 lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5606 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5607 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5608 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
5609 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5610 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
5611 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
5612 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5613 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
5614 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
5615 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5616
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5617 " 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
5618 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
5619 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
5620 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5621 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5622 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
5623 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5624 def T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5625 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
5626 a.val = 20
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5627 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5628 T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5629 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
5630 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
5631 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5632
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5633 " 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
5634 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
5635 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
5636 vim9script
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5637 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5638 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
5639 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
5640 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
5641 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
5642 endclass
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5643 def T()
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5644 assert_equal([1, 2], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5645 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
5646 A.var2 = [3, 4]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5647 A.var3 = {c: 3, d: 4}
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5648 assert_equal([3, 4], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5649 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
5650 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
5651 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5652 T()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5653 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5654 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
5655 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5656
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5657 " 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
5658 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
5659 var lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5660 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5661 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5662 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
5663 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
5664 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5665
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5666 A.svar1->add(3)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5667 A.svar2->add(4)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5668 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
5669 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
5670
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5671 def Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5672 A.svar1->add(7)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5673 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
5674 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
5675 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
5676 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5677 Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5678 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5679 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
5680
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5681 # 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
5682 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5683 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5684 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5685 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
5686 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
5687 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5688
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5689 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
5690 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5691 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
5692 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
5693
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5694 # 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
5695 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5696 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5697 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5698 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
5699 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
5700 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5701
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5702 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
5703 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5704 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
5705 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
5706
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5707 # 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
5708 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5709 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5710 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5711 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
5712 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
5713 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5714
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5715 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5716 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
5717 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5718 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5719 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5720 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
5721 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
5722
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5723 # 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
5724 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5725 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5726 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
5727 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
5728 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
5729 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5730
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5731 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5732 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
5733 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5734 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5735 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5736 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
5737 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
5738 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5739
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
5740 " 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
5741 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
5742 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
5743 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
5744
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5745 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
5746 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
5747 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
5748
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5749 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
5750 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
5751 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
5752 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
5753 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
5754
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5755 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
5756 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
5757 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
5758 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
5759 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
5760
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5761 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
5762 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
5763 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
5764
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5765 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
5766 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
5767 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
5768
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5769 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
5770 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
5771 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
5772 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5773 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
5774 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
5775
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5776 " 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
5777 " 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
5778 " 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
5779 " 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
5780 " 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
5781 " 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
5782 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5783 " 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
5784 " 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
5785 " 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
5786 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5787 " 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
5788 " 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
5789 " 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
5790 " 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
5791 " 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
5792 "
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 " 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
5794 " 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
5795 " 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
5796 " 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
5797 " 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
5798 " 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
5799 " 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
5800 " 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
5801 "
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 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
5803 " 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
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 "
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 " 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
5807 " 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
5808 " 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
5809 "
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 " 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
5811 " 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
5812 " 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
5813 " END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5814 " 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
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
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5817 " Test for abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5818 def Test_abstract_method()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5819 # Use two abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5820 var lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5821 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5822 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5823 def M1(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5824 return 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5825 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5826 abstract def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5827 abstract def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5828 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5829 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5830 def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5831 return 20
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5832 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5833 def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5834 return 30
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5835 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5836 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5837 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5838 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
5839 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5840 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5841
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5842 # 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
5843 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5844 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5845 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5846 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5847 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5848 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5849 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5850 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
5851 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
5852
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5853 # 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
5854 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5855 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5856 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5857 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5858 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5859 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5860 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5861 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
5862 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
5863
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5864 # 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
5865 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5866 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5867 interface A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5868 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5869 endinterface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5870 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
5871 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
5872 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5873 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5874 END
33700
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5875 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
5876
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5877 # 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
5878 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5879 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5880 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5881 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
5882 enddef
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5883 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5884 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5885 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
5886
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5887 # 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
5888 lines =<< trim END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5889 vim9script
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5890 interface A
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5891 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
5892 endinterface
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5893 END
275617cdd99f patch 9.0.2085: Vim9: abstract can be used in interface
Christian Brabandt <cb@256bit.org>
parents: 33698
diff changeset
5894 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
5895
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5896 # Abbreviate the "abstract" keyword
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5897 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5898 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5899 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5900 abs def Foo()
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, '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
5904
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5905 # 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
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 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5909 abstract this.val = 10
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 END
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5912 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
5913
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5914 # 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
5915 lines =<< trim END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5916 vim9script
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5917 abstract class A
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5918 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
5919 endclass
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5920 END
b076a133faf9 patch 9.0.2088: Vim9: still allows abstract static methods
Christian Brabandt <cb@256bit.org>
parents: 33704
diff changeset
5921 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
5922
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5923 # 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
5924 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5925 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5926 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5927 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
5928 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5929 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5930 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
5931 return []
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5932 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5933 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5934 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
5935 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
5936
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5937 # 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
5938 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5939 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5940 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5941 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
5942 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5943 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5944 def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5945 return [3, 5]
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5946 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5947 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5948 def Bar(c: B)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5949 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
5950 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5951 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5952 Bar(b)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5953 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5954 v9.CheckSourceSuccess(lines)
33698
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5955
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5956 # 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
5957 lines =<< trim END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5958 vim9script
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5959 abstract class A
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5960 static def Foo(): string
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5961 return 'foo'
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5962 enddef
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5963 endclass
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5964 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
5965 END
643db54ed3e7 patch 9.0.2084: Vim9: abstract static methods are possible
Christian Brabandt <cb@256bit.org>
parents: 33678
diff changeset
5966 v9.CheckSourceSuccess(lines)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5967 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5968
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5969 " 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
5970 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
5971 # 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
5972 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5973 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5974
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5975 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5976 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5977 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5978 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5979 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5980
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5981 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5982 def Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5983 Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5984 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5985 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5986
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5987 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5988 b.Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5989 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
5990 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
5991 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5992
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5993 " 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
5994 " script context.
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5995 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
5996 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5997 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
5998 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5999 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6000 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
6001 return ['a', 'b']
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6002 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6003 def Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6004 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
6005 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
6006 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6007 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6008
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6009 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6010 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
6011 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
6012 t_a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6013 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6014
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6015 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
6016 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
6017 a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6018 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6019 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6020 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
6021
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6022 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6023 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6024 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6025 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6026 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
6027 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6028 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6029 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6030
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6031 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
6032 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
6033 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
6034 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
6035
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6036 # def function context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6037 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6038 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6039 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6040 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
6041 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6042 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6043 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6044
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6045 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6046 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
6047 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
6048 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6049 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6050 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
6051 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
6052 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6053
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6054 def Test_class_variable()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6055 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6056 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6057
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6058 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6059 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
6060 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6061 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6062 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6063 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6064 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6065 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6066 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6067
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6068 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6069 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6070
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6071 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
6072 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6073 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6074 a.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6075 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6076 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6077
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6078 def T1(a1: A)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6079 a1.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6080 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6081 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6082 T1(b)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6083
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6084 A.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6085 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
6086 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6087 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6088
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6089 # 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
6090 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6091 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6092
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6093 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6094 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
6095 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6096
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6097 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6098 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6099 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6100 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6101 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6102 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6103 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
6104 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
6105
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6106 # 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
6107 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 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 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6113
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6114 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6115 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6116 var i = 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 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6120 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
6121 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
6122
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6123 # 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
6124 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6125 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6126
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6127 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6128 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
6129 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6130
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6131 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6132 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6133 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6134 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6135 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6136 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6137 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6138 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
6139 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
6140
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6141 # 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
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 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6151 var i = val
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 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6155 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6156 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
6157 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
6158
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6159 # 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
6160 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6161 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6162
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6163 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6164 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
6165 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6166 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6167 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6168 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
6169 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
6170
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6171 # 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
6172 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6173 vim9script
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 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6176 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
6177 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6178 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6179 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6180 END
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
6181 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
6182
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6183 # 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
6184 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6185 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6186
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6187 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6188 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
6189 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6190
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6191 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6192 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6193 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6194 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6195 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6196 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
6197 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
6198
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6199 # 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
6200 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6201 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6202
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6203 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6204 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
6205 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6206 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6207 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6208 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6209 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6210 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6211 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
6212 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
6213
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6214 # 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
6215 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6216 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6217
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6218 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6219 static val: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6220 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6221 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6222 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
6223
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6224 # 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
6225 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6226 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6227
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6228 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6229 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
6230 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6231 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6232 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
6233
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6234 # 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
6235 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6236 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6237
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6238 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6239 static val = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6240 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6241 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6242 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
6243
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6244 # 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
6245 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6246 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6247
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6248 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6249 static var: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6250 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6251 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6252 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
6253
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6254 # 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
6255 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6256 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6257
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6258 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6259 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
6260 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6261 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6262 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
6263
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6264 # 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
6265 lines =<< trim END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6266 vim9script
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6267
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6268 class A
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6269 static var = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6270 endclass
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6271 END
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6272 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
6273
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6274 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6275
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6276 " 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
6277 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
6278 # 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
6279 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6280 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6281 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6282 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
6283 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6284 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6285 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6286 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6287 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6288 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6289 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6290
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6291 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
6292 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
6293 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6294 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6295 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6296 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6297 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6298 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6299 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6300
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6301 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
6302 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6303 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6304
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6305 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
6306 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6307 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6308
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6309 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
6310 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
6311 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6312 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
6313 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6314 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
6315 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
6316 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
6317 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6318 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6319
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6320 # 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
6321 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6322 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6323 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6324 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
6325 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6326 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6327 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6328 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6329 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6330 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6331 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6332
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6333 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
6334 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
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(200, 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 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6339
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6340 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
6341 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6342 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6343
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6344 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
6345 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6346 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6347
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6348 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
6349 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
6350 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6351 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
6352 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6353 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
6354 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
6355 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
6356 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6357 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6358 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6359
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6360 " 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
6361 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
6362 # 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
6363 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6364 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6365 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6366 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6367 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6368 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6369 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6370 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6371 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
6372 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
6373
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6374 # 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
6375 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6376 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6377 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6378 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6379 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6380 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6381 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6382 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6383 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6384 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6385 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6386 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
6387 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
6388 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6389
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6390 " 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
6391 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
6392 # Duplicate instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6393 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6394 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6395 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6396 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6397 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6398 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6399 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6400 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6401 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
6402 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
6403
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6404 # 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
6405 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6406 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6407 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6408 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6409 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6410 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6411 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6412 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6413 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
6414 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
6415
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6416 # Duplicate class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6417 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6418 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6419 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6420 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6421 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6422 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6423 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6424 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6425 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
6426 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
6427
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6428 # 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
6429 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6430 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6431 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6432 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6433 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6434 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6435 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6436 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6437 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
6438 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
6439
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6440 # 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
6441 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6442 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6443 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6444 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6445 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6446 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6447 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6448 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6449 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
6450 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
6451 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6452
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6453 " 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
6454 " methods.
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6455 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
6456 # 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
6457 var 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 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 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6463 class B extends A
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 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6466 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6467 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6468 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6469 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
6470 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
6471
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6472 # Public method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6473 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6474 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6475 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6476 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6477 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6478 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6479 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6480 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6481 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6482 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6483 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6484 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6485 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
6486 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
6487 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6488
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6489 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
6490 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6491 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6492 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6493 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6494 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6495 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6496 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
6497 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
6498 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
6499 static def ClassMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6500 return 3
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6501 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6502 def ObjMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6503 return 4
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6504 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6505 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6506 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
6507 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
6508 var c = C.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6509 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
6510 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
6511 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6512 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
6513 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6514
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6515 " 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
6516 " 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
6517 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
6518 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
6519 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6520 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6521 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
6522 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6523 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
6524 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
6525
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6526 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
6527 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6528 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6529 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
6530 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6531 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
6532 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
6533
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6534 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
6535 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6536 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6537 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
6538 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6539 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
6540 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
6541
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6542 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
6543 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6544 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6545 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
6546 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6547 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
6548 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
6549
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6550 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
6551 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6552 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6553 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
6554 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6555 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
6556 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
6557
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6558 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
6559 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6560 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
6561 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
6562 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6563 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
6564 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
6565
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6566 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
6567 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6568 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
6569 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
6570 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6571 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
6572 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
6573
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6574 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
6575 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6576 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6577 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
6578 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6579 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6580 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
6581
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6582 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
6583 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6584 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
6585 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
6586 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6587 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
6588 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
6589 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6590
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6591 " 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
6592 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
6593 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
6594 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6595 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6596 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
6597 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
6598 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6599 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
6600 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
6601 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
6602 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6603 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
6604 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
6605 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
6606 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6607 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
6608 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
6609 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6610 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6611 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6612 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
6613
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6614 # 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
6615 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
6616 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6617 interface A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6618 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6619 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
6620 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6621 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
6622 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6623 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6624 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
6625
33278
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
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6629 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
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 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
6632 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
6633 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6634 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
6635 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
6636 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6637 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
6638 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
6639
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6640 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
6641 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6642 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
6643 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
6644 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6645 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
6646 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
6647 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6648 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
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 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6651 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6652 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
6653 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
6654
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6655 # 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
6656 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
6657 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6658 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
6659 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6660 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
6661 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6662 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
6663 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
6664
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6665 # 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
6666 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
6667 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6668 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
6669 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6670 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
6671 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6672 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
6673 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
6674
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6675 # 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
6676 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
6677 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6678 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
6679 endinterface
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 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
6681 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6682 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
6683 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
6684
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6685 # 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
6686 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
6687 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6688 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
6689 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6690 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
6691 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6692 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
6693 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6694 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
6695 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
6696
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6697 # 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
6698 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
6699 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6700 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6701 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
6702 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6703 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
6704 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
6705 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6706 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
6707 var val1: string
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6708 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
6709 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6710 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
6711 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
6712 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6713
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6714 " 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
6715 " 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
6716 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
6717 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
6718 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6719
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 Intf
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6721 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
6722 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
6723 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
6724 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
6725 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
6726 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
6727 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6728
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6729 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
6730 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
6731 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6732 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
6733 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
6734 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6735 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
6736 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
6737 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6738
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6739 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
6740 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
6741 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6742 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
6743 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
6744 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6745 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
6746 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
6747 endclass
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 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
6750 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
6751 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6752 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
6753 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
6754 enddef
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6755 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
6756 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
6757 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6758
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6759 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
6760 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
6761 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
6762 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
6763 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
6764 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
6765 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
6766 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6767
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6768 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
6769 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
6770 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
6771 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
6772 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
6773 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
6774 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
6775 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
6776 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6777 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
6778
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6779 # 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
6780 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
6781 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6782
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6783 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
6784 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
6785 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
6786 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
6787 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6788
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6789 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
6790 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
6791 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6792 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6793
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6794 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
6795 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
6796 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6797 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
6798 enddef
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()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6805 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6806 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6807 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
6808 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
6809
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6810 # 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
6811 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
6812 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6813
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6814 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
6815 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
6816 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
6817 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
6818 endinterface
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 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
6821 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
6822 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
6823 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6824 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
6825 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6826 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6827
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6828 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
6829 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
6830 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6831 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
6832 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6833 endclass
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 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
6836 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
6837 enddef
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 F1()
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6839 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6840 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6841 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
6842 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
6843
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6844 # 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
6845 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
6846 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6847
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6848 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6849 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
6850 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
6851 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
6852 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6853
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6854 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6855 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
6856 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6857
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6858 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
6859 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
6860 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
6861 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6862
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6863 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
6864 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
6865 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
6866 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6867 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
6868 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
6869
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6870 # 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
6871 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
6872 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6873
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6874 interface Intf
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6875 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
6876 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
6877 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
6878 endinterface
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 A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6881 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
6882 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
6883 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6884
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6885 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
6886 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
6887 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
6888 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6889
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6890 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
6891 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
6892 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
6893 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6894 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
6895 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
6896 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6897
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6898 " 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
6899 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
6900 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
6901 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6902 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6903 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
6904 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
6905 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6906 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
6907 var n2: number
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6908 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
6909 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
6910 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
6911 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6912 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
6913 var n1 = 10
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6914 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
6915 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
6916 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
6917 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6918 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
6919 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
6920 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6921 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6922 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
6923 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
6924 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
6925 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6926 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
6927 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
6928 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
6929 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
6930 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
6931 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6932 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
6933 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
6934 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
6935 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6936 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
6937 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6938
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6939 " 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
6940 " 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
6941 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
6942 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
6943 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6944 interface A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6945 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
6946 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6947 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
6948 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
6949 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6950 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
6951 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
6952 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 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
6954
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6955 # 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
6956 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
6957 vim9script
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 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 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
6960 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6961 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
6962 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
6963 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6964 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
6965 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
6966 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
6967 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6968
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6969 " 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
6970 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
6971 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
6972 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6973
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6974 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6975 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
6976 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6977
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6978 class B
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6979 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
6980 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6981
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6982 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6983 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
6984 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6985
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6986 class D
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
6987 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
6988 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6989
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6990 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
6991 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
6992 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6993
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6994 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
6995 T(d)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6996 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
6997 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
6998 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6999
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7000 " 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
7001 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
7002 # 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
7003 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
7004 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7005
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7006 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7007 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7008 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
7009 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7010 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7011
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7012 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7013 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7014 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7015 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
7016
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7017 # 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
7018 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7019 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7020
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7021 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7022 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7023 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
7024 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7025 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7026
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7027 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7028 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7029 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7030 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7031 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7032 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7033 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
7034
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7035 # 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
7036 # script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7037 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7038 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7039
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7040 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7041 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7042 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
7043 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7044
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7045 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
7046 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
7047 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7048 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7049 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7050
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7051 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7052 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7053 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7054 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
7055
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7056 # 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
7057 # def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7058 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7059 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7060
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7061 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7062 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7063 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
7064 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7065
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7066 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
7067 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
7068 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7069 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7070 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7071
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7072 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7073 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7074 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7075 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7076 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7077 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7078 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
7079 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7080
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7081 " 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
7082 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
7083 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
7084 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7085
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7086 class Context
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7087 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
7088 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
7089 return this.state
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7090 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7091 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7092
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7093 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
7094 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
7095 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
7096 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
7097
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7098 def F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7099 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
7100 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
7101 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7102 F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7103 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
7104 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
7105 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
7106 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7107 v9.CheckSourceSuccess(lines)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7108 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
7109
33337
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7110 " 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
7111 " 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
7112 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
7113 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
7114 vim9script
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7115
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7116 class Context
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7117 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7118
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7119 class Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7120 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7121
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7122 def Failure(): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7123 return Result.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7124 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7125
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7126 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
7127 return Failure()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7128 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7129
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7130 def Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7131 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
7132 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
7133 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7134
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7135 Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7136 END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7137 v9.CheckSourceSuccess(lines)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7138 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
7139
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7140 " 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
7141 def Test_duplicate_variable()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7142 # 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
7143 var lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7144 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7145 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7146 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
7147 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
7148 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7149 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7150 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7151 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
7152
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7153 # 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
7154 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7155 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7156 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7157 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
7158 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
7159 def F1()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7160 echo this.sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7161 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7162 static def F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7163 echo sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7164 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7165 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7166 A.F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7167 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7168 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
7169
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7170 # 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
7171 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7172 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7173 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7174 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
7175 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
7176 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7177 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7178 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7179 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7180 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7181 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
7182 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7183
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7184 " 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
7185 def Test_reserved_varname()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7186 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
7187 '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
7188 '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
7189
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7190 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
7191 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7192 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7193 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
7194 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7195 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7196 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7197 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
7198
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7199 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7200 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7201 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7202 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
7203 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7204 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7205 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7206 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7207 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7208 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
7209
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7210 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7211 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7212 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7213 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
7214 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7215 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7216 def F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7217 echo this.{kword}
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7218 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7219 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7220 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7221 o.F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7222 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7223 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
7224
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7225 # 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
7226 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
7227 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
7228 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7229 class C
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7230 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
7231 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7232 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
7233 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
7234 endif
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7235 endfor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7236 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
7237
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7238 " 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
7239 " 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
7240 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
7241 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
7242 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7243
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7244 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7245 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7246 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
7247 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7248 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
7249 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7250
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7251 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7252 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
7253 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7254 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7255 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7256
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7257 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
7258 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
7259 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7260 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7261 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7262 END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7263 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
7264
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7265 lines =<< trim END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7266 vim9script
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7267
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7268 class A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7269 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7270 class B extends A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7271 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7272 class C extends B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7273 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7274
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7275 class Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7276 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
7277 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7278 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7279 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7280
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7281 class Bar extends Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7282 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
7283 return C.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7284 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7285 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7286 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7287 v9.CheckSourceSuccess(lines)
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7288
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7289 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7290 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7291
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7292 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7293 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7294 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
7295 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7296 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
7297 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7298
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7299 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7300 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
7301 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7302 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7303 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7304
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7305 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
7306 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
7307 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7308 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7309 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7310 END
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
7311 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
7312
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7313 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7314 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7315
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7316 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7317 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7318 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
7319 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7320 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
7321 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7322
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7323 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7324 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
7325 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7326 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7327 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7328
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7329 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
7330 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
7331 return A.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7332 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7333 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7334 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7335 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
7336
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7337 # check varargs type mismatch
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7338 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7339 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7340
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7341 class B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7342 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
7343 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7344 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7345 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7346 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
7347 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7348 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7349 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7350 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
7351 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
7352
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7353 " 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
7354 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
7355 " 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
7356 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7357 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7358 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7359 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
7360 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7361 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7362 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7363 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
7364 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7365 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7366 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7367 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7368 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
7369
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7370 " 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
7371 " class def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7372 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7373 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7374 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
7375 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7376 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7377 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7378 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
7379 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7380 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7381 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7382 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7383 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7384 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7385 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7386 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7387 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
7388
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7389 " 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
7390 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7391 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7392 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7393 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
7394 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7395 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7396 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7397 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
7398 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7399 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7400 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7401 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7402 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7403 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7404 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7405 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
7406
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7407 " 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
7408 " 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
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 = 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 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
7423 " 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
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 = 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 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
7442 " 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
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 = 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 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
7460 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7461 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7462 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
7463 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7464 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7465 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7466 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
7467 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
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()
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7470 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
7471 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7472 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7473 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
7474 A.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7475 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
7476 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
7477 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7478 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7479 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
7480 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7481 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7482
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7483 " 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
7484 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7485 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7486 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
7487 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7488 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7489 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7490 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
7491 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
7492
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7493 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
7494 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
7495 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7496 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
7497 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
7498 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
7499 Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7500 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
7501 enddef
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 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7504 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7505 a.Bar()
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 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7508 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7509 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7510 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7511
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7512 " 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
7513 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7514 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7515 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
7516 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7517 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7518 class A
33942
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 Fn: any = Foo
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7520 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
7521 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7522
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7523 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
7524 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
7525 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7526 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
7527 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
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 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
7531 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7532 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7533 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7534 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7535 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7536 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7537 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
7538
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7539 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
7540 vim9script
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
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 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
7543 endclass
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7544 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
7545 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
7546 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
7547 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
7548 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
7549 END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7550 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
7551 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7552
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7553 " 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
7554 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
7555 " 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
7556 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7557 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7558 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7559 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
7560 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7561 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7562 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7563 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
7564 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7565 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7566 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7567 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7568 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7569 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
7570
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7571 " 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
7572 " object def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7573 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7574 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7575 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
7576 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7577 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7578 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7579 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
7580 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7581 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7582 this.Fn = Foo
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 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7585 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7586 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7587 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7588 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7589 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
7590
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7591 " 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
7592 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7593 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7594 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7595 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
7596 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7597 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7598 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7599 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
7600 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7601 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7602 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7603 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7604 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7605 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7606 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7607 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7608 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7609 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
7610
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7611 " 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
7612 " 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
7613 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7614 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7615 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
7616 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7617 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7618 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7619 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
7620 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7621 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7622 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7623 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7624 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7625 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
7626
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7627 " 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
7628 " 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
7629 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7630 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7631 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
7632 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7633 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7634 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7635 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
7636 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7637 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7638 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7639 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7640 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7641 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7642 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7643 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7644 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7645 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
7646
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7647 " 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
7648 " 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
7649 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7650 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7651 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
7652 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7653 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7654 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7655 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
7656 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7657 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7658 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7659 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7660 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7661 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7662 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7663 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7664 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7665 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
7666
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7667 " 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
7668 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7669 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7670 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
7671 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7672 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7673 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7674 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
7675 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
7676 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7677
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7678 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7679 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
7680 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
7681 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7682 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7683 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
7684 a.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7685 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
7686 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
7687 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7688 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7689 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
7690 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7691 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7692
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7693 " 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
7694 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7695 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7696 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
7697 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7698 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7699 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7700 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
7701 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
7702
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7703 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
7704 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
7705 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7706 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
7707 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
7708 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
7709 this.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7710 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
7711 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7712 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7713
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7714 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7715 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7716 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7717 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7718 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7719 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7720 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7721 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7722
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7723 " 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
7724 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7725 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7726 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
7727 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7728 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7729 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7730 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
7731 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
7732 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7733
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7734 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7735 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
7736 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
7737 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7738 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
7739 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
7740 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
7741 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7742 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
7743 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7744 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7745 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7746 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7747 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7748 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7749 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7750 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7751
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7752 " 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
7753 " 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
7754 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
7755 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
7756 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7757 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7758 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
7759 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
7760 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
7761 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
7762 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7763 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
7764 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
7765 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7766 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7767 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
7768 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
7769 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7770 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
7771 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7772
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7773 " 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
7774 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
7775 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
7776 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7777 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7778 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
7779 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
7780 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
7781 return val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7782 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7783 val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7784 return Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7785 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7786 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7787 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
7788 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7789 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
7790 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7791
33517
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7792 " 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
7793 " 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
7794 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
7795 var lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7796 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7797 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7798 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7799 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7800 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7801
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7802 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7803 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7804 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7805
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7806 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
7807 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7808 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
7809
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7810 lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7811 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7812 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7813 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7814 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7815 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7816
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7817 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7818 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7819 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7820
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7821 def Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7822 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
7823 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7824 Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7825 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7826 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
7827 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7828
33598
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7829 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
7830 var lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7831 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7832
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7833 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7834 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7835 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7836 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7837 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7838 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7839
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7840 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
7841 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
7842 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
7843 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7844 v9.CheckSourceSuccess(lines)
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7845
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7846 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7847 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7848
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7849 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7850 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7851 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7852 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7853 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7854 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7855
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7856 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
7857 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
7858 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7859 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
7860
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7861 lines =<< trim END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7862 vim9script
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7863
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7864 class A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7865 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7866 class B extends A
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7867 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7868 class C extends B
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7869 endclass
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7870
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7871 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
7872 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
7873 END
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7874 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
7875 enddef
1fcb7c9dc546 patch 9.0.2043: Vim9: issue with funcref assignmentand varargs
Christian Brabandt <cb@256bit.org>
parents: 33587
diff changeset
7876
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7877 " 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
7878 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
7879 # 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
7880 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
7881 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7882 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7883 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
7884 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
7885 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
7886 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
7887 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7888 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7889 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
7890 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
7891 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
7892 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7893 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
7894 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
7895 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
7896 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
7897 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7898 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
7899
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7900 # 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
7901 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
7902 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7903 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7904 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
7905 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
7906 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
7907 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
7908 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7909 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7910 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
7911 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
7912 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
7913 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7914 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
7915 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
7916 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
7917 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
7918 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
7919 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7920 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
7921 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7922
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7923 " 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
7924 def Test_object_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7925 # 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
7926 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7927 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7928 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7929 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7930 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7931 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7932 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7933 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7934 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7935 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7936 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
7937 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7938 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7939 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7940 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7941
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7942 # 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
7943 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7944 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7945 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7946 def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7947 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7948 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7949 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7950 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7951 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7952 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
7953 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7954 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7955
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7956 # 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
7957 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7958 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7959 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
7960 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
7961 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7962 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7963 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7964 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7965 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
7966 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
7967 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
7968 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7969 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7970
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7971 # 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
7972 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7973 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7974 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7975 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7976 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7977 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7978 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7979 var Fn = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7980 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
7981 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7982 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7983 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7984 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7985 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7986 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7987
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7988 # 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
7989 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7990 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7991 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7992 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
7993 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7994 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7995 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7996 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7997 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
7998 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
7999 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8000 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8001
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8002 # 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
8003 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8004 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8005 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8006
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8007 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
8008 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8009 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8010
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8011 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8012 def Double(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8013 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8014 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8015 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8016
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8017 const math = Math.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8018 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
8019 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8020 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8021
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8022 # 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
8023 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8024 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8025 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8026 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8027 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8028 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8029 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8030 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8031 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8032 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8033 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8034 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8035 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
8036
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8037 # 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
8038 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8039 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8040 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8041 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8042 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8043 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8044 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8045 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8046 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8047 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
8048
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8049 # 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
8050 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8051 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8052 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8053 def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8054 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8055 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8056 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8057 var Fn = this._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8058 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
8059 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8060 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8061 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8062 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8063 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8064 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
8065
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8066 # 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
8067 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8068 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8069 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8070 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
8071 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8072 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8073 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8074 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8075
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8076 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
8077 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
8078 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8079
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8080 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
8081 Bar(a)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8082 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
8083 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8084 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8085 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8086
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8087 " 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
8088 def Test_class_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8089 # 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
8090 var 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 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8094 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8095 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8096 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8097 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8098 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8099 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
8100 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8101 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8102 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8103 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8104
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8105 # 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
8106 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8107 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8108 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8109 static def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8110 return {a: 1, b: 2}
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 Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8114 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
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)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8117
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8118 # 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
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 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
8123 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
8124 return 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 A.val = 567
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8128 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
8129 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
8130 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8131 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8132
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8133 # 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
8134 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8135 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8136 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8137 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
8138 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8139 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8140 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8141 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
8142 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
8143 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8144 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8145
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8146 # 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
8147 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8148 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8149 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8150 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8151 return [3, 2, 1]
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 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8154 var Fn = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8155 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
8156 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8157 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8158 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8159 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8160 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8161
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8162 # 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
8163 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8164 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8165 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8166
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8167 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
8168 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8169 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8170
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8171 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8172 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
8173 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8174 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8175 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8176
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8177 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
8178 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8179 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8180
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8181 # 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
8182 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8183 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8184 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8185 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8186 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8187 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8188 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8189 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8190 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8191 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8192 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8193 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
8194
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8195 # 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
8196 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8197 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8198 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8199 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8200 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8201 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8202 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8203 END
33738
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8204 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
8205
2172872dfbcd patch 9.0.2096: Vim9: confusing usage of private
Christian Brabandt <cb@256bit.org>
parents: 33708
diff changeset
8206 # 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
8207 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8208 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8209 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8210 static def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8211 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8212 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8213 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8214 var Fn = _Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8215 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
8216 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8217 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8218 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8219 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8220 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
8221
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8222 # 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
8223 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8224 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8225 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8226 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
8227 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
8228 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8229 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8230 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8231
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8232 def Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8233 A.val = 468
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8234 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
8235 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8236 Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8237 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
8238 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
8239 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8240 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8241
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8242 " 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
8243 def Test_object_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8244 # 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
8245 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8246 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8247 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8248 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8249 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8250
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8251 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8252 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
8253 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8254 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
8255 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8256 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8257
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8258 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8259 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8260 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8261 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8262
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8263 # 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
8264 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8265 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8266 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8267 return n * 10
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
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8270 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8271 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
8272 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8273
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8274 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8275 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8276 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
8277 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8278 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8279 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8280 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8281
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8282 # 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
8283 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8284 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8285 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8286 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8287 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8288
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8289 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8290 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
8291 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8292
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8293 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8294 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
8295 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8296 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8297
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8298 # 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
8299 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8300 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8301 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8302 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8303 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
8304 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8305 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8306 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8307 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8308 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
8309 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8310 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8311
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8312 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8313 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8314 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8315 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8316
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8317 # 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
8318 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8319 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8320 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8321 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8322 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
8323 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8324 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8325 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8326 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8327
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8328 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8329 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8330 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
8331 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8332 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8333 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8334 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8335
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8336 # 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
8337 # level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8338 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8339 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8340 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8341 var Cb = this.Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8342 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8343 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8344 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8345 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8346
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8347 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8348 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
8349 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8350 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8351 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8352
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8353 " 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
8354 def Test_class_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8355 # 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
8356 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8357 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8358 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8359 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8360 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8361
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8362 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8363 static var Cb = Foo
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8364 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8365 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8366 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8367 endclass
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 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8370 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8371 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8372
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8373 # 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
8374 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8375 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8376 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8377 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8378 enddef
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 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8381 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
8382 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8383
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8384 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8385 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
8386 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8387 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8388 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8389 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8390
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8391 # 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
8392 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8393 vim9script
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
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8398 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8399 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
8400 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8401
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8402 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
8403 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8404 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8405
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8406 # 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
8407 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8408 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 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8411 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
8412 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
8413 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8414 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8415 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8416 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8417 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8418 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8419 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8420 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8421 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8422
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8423 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8424 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8425 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8426 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8427
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8428 # 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
8429 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8430 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8431 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8432 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
8433 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
8434 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8435 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8436 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8437 Cb = Foo
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 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8440
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8441 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8442 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8443 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
8444 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8445 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8446 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8447 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8448
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8449 # 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
8450 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8451 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8452 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8453 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
8454 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
8455 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8456 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8457 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8458 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8459 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8460 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8461
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8462 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8463 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
8464 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8465 v9.CheckSourceSuccess(lines)
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
33587
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8468 " 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
8469 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
8470 # 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
8471 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
8472 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8473
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8474 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8475 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
8476 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
8477
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8478 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
8479 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
8480 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
8481 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8482
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8483 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
8484 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
8485 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8486 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8487
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8488 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
8489 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
8490 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
8491 {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
8492 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
8493 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
8494 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
8495 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
8496 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
8497 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
8498 {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
8499 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
8500 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
8501 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
8502 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
8503 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8504 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
8505
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8506 # 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
8507 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
8508 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8509
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8510 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8511 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
8512 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
8513
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8514 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
8515 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
8516 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
8517 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8518
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8519 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
8520 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
8521 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8522 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8523
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8524 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
8525 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
8526 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
8527 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
8528 {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
8529 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
8530 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
8531 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
8532 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
8533 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
8534 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
8535 {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
8536 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
8537 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
8538 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
8539 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
8540 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8541 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8542 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8543 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
8544 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8545
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8546 " 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
8547 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
8548 # 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
8549 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
8550 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8551
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8552 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8553 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
8554 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
8555
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8556 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
8557 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
8558 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
8559 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8560
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8561 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
8562 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
8563 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8564 endclass
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 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
8567 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
8568 {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
8569 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
8570 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
8571 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
8572 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
8573 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
8574 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
8575 {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
8576 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
8577 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
8578 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
8579 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
8580 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8581 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
8582
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8583 # 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
8584 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
8585 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8586
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8587 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8588 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
8589 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
8590
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8591 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
8592 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
8593 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
8594 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8595
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8596 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
8597 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
8598 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8599 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8600
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8601 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
8602 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
8603 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
8604 {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
8605 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
8606 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
8607 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
8608 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
8609 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
8610 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
8611 {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
8612 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
8613 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
8614 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
8615 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
8616 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8617 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8618 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8619 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
8620 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8621
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8622 " 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
8623 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
8624 # 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
8625 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
8626 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8627
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8628 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8629 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
8630 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
8631 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
8632 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8633 endclass
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 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
8636 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
8637 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
8638 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
8639 :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
8640 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
8641 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8642 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
8643 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8644 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
8645
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8646 # 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
8647 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
8648 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8649
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8650 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8651 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
8652 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
8653 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
8654 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8655 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8656
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8657 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
8658 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
8659 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
8660 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
8661 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
8662 :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
8663 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
8664 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8665 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
8666 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8667 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8668 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8669 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
8670 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8671
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8672 " 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
8673 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
8674 # 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
8675 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
8676 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8677
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8678 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8679 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
8680 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
8681 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
8682 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8683 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8684
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8685 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
8686 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
8687 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
8688 :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
8689 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
8690 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8691 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
8692 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8693 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
8694
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8695 # 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
8696 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
8697 vim9script
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8698
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8699 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8700 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
8701 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
8702 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
8703 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8704 endclass
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8705
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8706 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
8707 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
8708 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
8709 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
8710 :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
8711 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
8712 endwhile
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8713 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
8714 enddef
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8715 Foo()
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8716 END
c470d4fd5eba patch 9.0.2038: Vim9: object method funcref not cleaned up after use
Christian Brabandt <cb@256bit.org>
parents: 33568
diff changeset
8717 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
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
33611
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8720 " 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
8721 " operator.
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8722 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
8723 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
8724 vim9script
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8725 class Tests
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8726 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
8727 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
8728 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
8729 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
8730 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
8731
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8732 static def Str(): string
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8733 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
8734 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8735
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8736 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
8737 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
8738 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8739
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8740 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
8741 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
8742 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8743
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8744 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
8745 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
8746 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8747
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8748 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
8749 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
8750 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
8751 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
8752 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
8753 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
8754 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
8755 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
8756 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
8757 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
8758 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
8759
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8760 # 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
8761 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8762 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
8763 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
8764
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8765 # 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
8766 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8767 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
8768 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8769 endclass
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8770
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8771 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
8772 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
8773 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
8774 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
8775 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
8776 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
8777 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
8778 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
8779 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
8780 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
8781 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
8782 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
8783 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
8784
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8785 # 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
8786 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8787 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
8788 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
8789
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8790 # 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
8791 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8792 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
8793 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8794
33618
698de9399942 patch 9.0.2051: Vim9: wrong error for non-existing object var
Christian Brabandt <cb@256bit.org>
parents: 33611
diff changeset
8795 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
8796 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
8797 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
8798 TestOps2()
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 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
8801 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
8802 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
8803 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
8804 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
8805 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
8806 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
8807 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
8808 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
8809 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
8810 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
8811 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
8812
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8813 # 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
8814 var l = range(10)
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8815 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
8816 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
8817
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8818 # 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
8819 var d = {hello: 'abc'}
53416c49a7ab patch 9.0.2059: outstanding exceptions may be skipped
Christian Brabandt <cb@256bit.org>
parents: 33627
diff changeset
8820 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
8821 END
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8822 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
8823 enddef
de690130ba43 patch 9.0.2049: Vim9: not recognizing qualified class vars for infix ops
Christian Brabandt <cb@256bit.org>
parents: 33598
diff changeset
8824
33668
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8825 " 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
8826 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
8827 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
8828 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8829
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8830 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
8831 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
8832 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8833
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8834 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
8835 def ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8836 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
8837 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
8838 [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
8839 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
8840 [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
8841 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
8842 [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
8843 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
8844 [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
8845 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
8846 [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
8847 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
8848 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8849
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8850 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
8851 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
8852 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
8853 [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
8854 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
8855 [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
8856 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
8857 [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
8858 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
8859 [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
8860 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
8861 [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
8862 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
8863 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8864
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8865 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8866 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8867
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8868 def newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8869 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
8870 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8871 [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
8872 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
8873 [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
8874 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
8875 [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
8876 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
8877 [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
8878 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
8879 [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
8880 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
8881 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8882 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8883
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8884 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
8885 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
8886 var z: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8887 [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
8888 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
8889 [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
8890 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
8891 [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
8892 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
8893 [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
8894 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
8895 [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
8896 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
8897 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8898
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8899 Test.newMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8900 Test.new().ObjMethodTests()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8901 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
8902 DefFuncTests(Test.new())
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8903
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8904 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
8905 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
8906 [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
8907 [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
8908 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
8909 END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8910 v9.CheckSourceSuccess(lines)
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8911
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8912 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8913 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8914
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8915 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8916 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
8917
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8918 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8919 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8920
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8921 def Foo()
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.a, z] = [{}, 10]
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8924 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8925 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8926
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8927 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
8928 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8929 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
8930 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
8931
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8932 lines =<< trim END
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8933 vim9script
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8934
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8935 class A
33942
3bba09502b8d patch 9.0.2167: Vim9: not consistently using :var for declarations
Christian Brabandt <cb@256bit.org>
parents: 33936
diff changeset
8936 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
8937
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8938 def new()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8939 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8940
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8941 def Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8942 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
8943 var y: number
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8944 [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
8945 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8946 endclass
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8947
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8948 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
8949 a.Foo()
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8950 END
33886
cd7acb9bc4fd patch 9.0.2152: Using type unknown for List/Dict containers
Christian Brabandt <cb@256bit.org>
parents: 33829
diff changeset
8951 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
8952 enddef
fcc8296f36eb patch 9.0.2072: Vim9: no nr2str conversion in list-unpack
Christian Brabandt <cb@256bit.org>
parents: 33636
diff changeset
8953
33829
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8954 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
8955 # 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
8956 # of Vim.
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8957 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
8958 vim9script
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8959
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8960 class A
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8961 def new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8962 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
8963 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8964
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8965 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
8966 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8967
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8968 def F00()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8969 this.F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8970 this.F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8971 this.F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8972 this.F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8973 this.F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8974 this.F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8975 this.F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8976 this.F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8977 this.F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8978 this.F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8979 this.F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8980 this.F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8981 this.F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8982 this.F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8983 this.F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8984 this.F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8985 this.F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8986 this.F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8987 this.F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8988 this.F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8989 this.F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8990 this.F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8991 this.F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8992 this.F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8993 this.F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8994 this.F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8995 this.F27()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8996 this.F28()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8997 this.F29()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8998 this.F30()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
8999 this.F31()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9000 this.F32()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9001 this.F33()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9002 this.F34()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9003 this.F35()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9004 this.F36()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9005 this.F37()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9006 this.F38()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9007 this.F39()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9008 this.F40()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9009 this.F41()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9010 this.F42()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9011 this.F43()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9012 this.F44()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9013 this.F45()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9014 this.F46()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9015 this.F47()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9016 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9017
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9018 def F01()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9019 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9020 def F02()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9021 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9022 def F03()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9023 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9024 def F04()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9025 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9026 def F05()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9027 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9028 def F06()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9029 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9030 def F07()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9031 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9032 def F08()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9033 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9034 def F09()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9035 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9036 def F10()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9037 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9038 def F11()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9039 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9040 def F12()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9041 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9042 def F13()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9043 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9044 def F14()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9045 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9046 def F15()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9047 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9048 def F16()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9049 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9050 def F17()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9051 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9052 def F18()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9053 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9054 def F19()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9055 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9056 def F20()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9057 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9058 def F21()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9059 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9060 def F22()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9061 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9062 def F23()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9063 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9064 def F24()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9065 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9066 def F25()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9067 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9068 def F26()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9069 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9070 def F27()
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 F28()
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 F29()
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 F30()
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 F31()
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 F32()
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 F33()
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 F34()
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 F35()
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 F36()
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 F37()
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 F38()
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 F39()
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 F40()
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 F41()
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 F42()
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 F43()
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 F44()
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 F45()
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 F46()
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 F47()
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 endclass
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9113
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9114 A.new()
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9115 END
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9116 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
9117 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
9118 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
9119 enddef
f0132690cdf9 patch 9.0.2129: [security]: use-after-free in call_dfunc()
Christian Brabandt <cb@256bit.org>
parents: 33738
diff changeset
9120
33951
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9121 " 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
9122 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
9123 # 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
9124 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
9125 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9126 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
9127 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
9128 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
9129 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
9130 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9131 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9132 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
9133 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9134 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
9135
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9136 # 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
9137 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
9138 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9139 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
9140 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
9141 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
9142 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
9143 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
9144 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9145 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9146 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
9147 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
9148 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
9149 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9150 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
9151
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9152 # 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
9153 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
9154 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9155 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
9156 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
9157 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9158 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
9159 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9160 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
9161
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9162 # 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
9163 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
9164 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9165 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
9166 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
9167 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
9168 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
9169 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9170 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9171 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
9172 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9173 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
9174
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 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
9176 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 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
9180 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9181 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
9182 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
9183 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9184 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
9185
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9186 # 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
9187 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
9188 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9189 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
9190 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
9191 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
9192 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
9193 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9194 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9195 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
9196 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9197 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
9198
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9199 # 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
9200 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
9201 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9202 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
9203 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
9204 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9205 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
9206 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
9207 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9208 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9209 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9210 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
9211
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9212 # 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
9213 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
9214 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9215 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
9216 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
9217 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
9218 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
9219 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9220 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
9221 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
9222 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
9223 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9224 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9225 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
9226 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
9227 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
9228 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
9229 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9230 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
9231
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9232 # 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
9233 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9234 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
9235 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9236 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
9237 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
9238 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
9239 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
9240 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9241 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9242 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
9243 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
9244 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9245 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
9246
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9247 # 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
9248 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
9249 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9250 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
9251 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
9252 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9253 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
9254 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
9255 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
9256 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
9257 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9258 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
9259
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9260 # 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
9261 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
9262 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9263 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
9264 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
9265 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9266 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
9267 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
9268 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
9269 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
9270 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
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 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 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9274 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
9275
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9276 # 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
9277 # function
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9278 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
9279 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9280 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
9281 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
9282 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
9283 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
9284 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
9285 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9286 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9287 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
9288 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
9289 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
9290 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9291 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
9292
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9293 # 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
9294 # 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
9295 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
9296 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9297 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
9298 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
9299 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9300 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
9301 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
9302 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9303 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
9304
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9305 # 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
9306 # 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
9307 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
9308 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9309 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
9310 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
9311 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
9312 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
9313 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9314 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9315 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
9316 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
9317 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9318 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
9319
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9320 # 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
9321 # 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
9322 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
9323 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9324 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
9325 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
9326 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9327 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
9328 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
9329 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
9330 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9331 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9332 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9333 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
9334
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9335 # 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
9336 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
9337 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9338 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
9339 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
9340 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9341 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
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.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
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 # 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
9346 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
9347 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9348 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
9349 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
9350 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9351 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
9352 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9353 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
9354
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9355 # 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
9356 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
9357 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9358 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
9359 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
9360 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9361 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
9362 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9363 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
9364
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9365 # 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
9366 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
9367 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9368 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
9369 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
9370 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9371 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9372 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
9373
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9374 # 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
9375 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
9376 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9377 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
9378 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
9379 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9380 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9381 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9382 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
9383
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9384 # 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
9385 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
9386 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9387 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
9388 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
9389 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9390 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9391 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9392 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
9393 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9394
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9395 " 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
9396 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
9397 # 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
9398 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
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 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
9402 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
9403 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
9404 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9405 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9406 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
9407 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9408 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
9409
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9410 # 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
9411 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
9412 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9413 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
9414 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
9415 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
9416 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
9417 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
9418 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9419 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9420 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
9421 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
9422 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
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.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
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 # 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
9427 # 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
9428 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
9429 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9430 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
9431 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
9432 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
9433 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
9434 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9435 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
9436 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
9437 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9438 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9439 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
9440 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9441 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
9442
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9443 # 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
9444 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
9445 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9446 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
9447 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
9448 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9449 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
9450 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 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
9452
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9453 # 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
9454 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
9455 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9456 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
9457 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
9458 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
9459 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
9460 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9461 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9462 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
9463 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 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
9465
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9466 # 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
9467 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
9468 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9469 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
9470 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
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 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
9473 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
9474 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9475 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
9476
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9477 # 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
9478 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
9479 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9480 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
9481 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
9482 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
9483 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
9484 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9485 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9486 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
9487 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9488 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
9489
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9490 # 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
9491 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
9492 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9493 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
9494 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
9495 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9496 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
9497 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
9498 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9499 defcompile
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9500 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9501 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
9502
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9503 # 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
9504 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
9505 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9506 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
9507 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
9508 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
9509 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
9510 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9511 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
9512 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
9513 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9514 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9515 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
9516 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
9517 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
9518 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9519 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
9520
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9521 # 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
9522 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
9523 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9524 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
9525 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
9526 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
9527 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
9528 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9529 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
9530 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
9531 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9532 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9533 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
9534 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
9535 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9536 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
9537
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9538 # 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
9539 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
9540 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9541 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
9542 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
9543 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
9544 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
9545 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9546 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9547 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
9548 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
9549 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9550 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
9551
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9552 # 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
9553 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
9554 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9555 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
9556 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
9557 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9558 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
9559 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
9560 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9561 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
9562
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9563 # 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
9564 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
9565 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9566 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
9567 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
9568 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9569 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
9570 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
9571 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9572 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
9573
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9574 # 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
9575 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
9576 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9577 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
9578 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
9579 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9580 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
9581 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
9582 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
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 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9585 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9586 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
9587
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9588 # 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
9589 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
9590 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9591 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
9592 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
9593 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9594 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
9595 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
9596 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
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 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9599 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9600 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
9601
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9602 # 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
9603 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
9604 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9605 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
9606 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
9607 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
9608 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
9609 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9610 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9611 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
9612 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
9613 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9614 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
9615
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9616 # 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
9617 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
9618 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9619 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
9620 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
9621 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
9622 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
9623 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9624 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9625 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
9626 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
9627 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 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
9629
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9630 # 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
9631 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
9632 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9633 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
9634 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
9635 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9636 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
9637 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
9638 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9639 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
9640
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9641 # 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
9642 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
9643 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9644 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
9645 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
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 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
9648 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9649 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9650 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
9651 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
9652 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9653 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
9654
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9655 # 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
9656 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
9657 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9658 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
9659 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
9660 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9661 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
9662 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
9663 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
9664 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9665 Foo()
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9666 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9667 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
9668
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9669 # 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
9670 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
9671 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9672 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
9673 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
9674 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9675 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
9676 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9677 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
9678
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9679 # 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
9680 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
9681 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9682 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
9683 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
9684 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9685 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
9686 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9687 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
9688
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9689 # 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
9690 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
9691 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9692 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
9693 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
9694 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9695 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
9696 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9697 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
9698
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9699 # 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
9700 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
9701 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9702 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
9703 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
9704 endinterface
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9705 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9706 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
9707
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9708 # 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
9709 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
9710 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9711 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
9712 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
9713 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9714 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9715 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9716 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
9717
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9718 # 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
9719 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
9720 vim9script
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9721 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
9722 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
9723 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9724 endclass
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9725 END
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9726 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
9727 enddef
45a50fd59a73 patch 9.0.2170: Vim9: no support for const/final class/objects vars
Christian Brabandt <cb@256bit.org>
parents: 33942
diff changeset
9728
34112
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9729 " 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
9730 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
9731 # 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
9732 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
9733 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9734 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9735 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9736 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
9737 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9738 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9739 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9740 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9741 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
9742 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9743 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9744 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9745 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9746 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9747 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
9748
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9749 # 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
9750 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
9751 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9752 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9753 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9754 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9755 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9756 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9757 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9758 def Bar()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9759 yyy
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9760 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9761 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9762 defcompile B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9763 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9764 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
9765
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9766 # 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
9767 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
9768 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9769 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9770 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9771 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9772 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9773 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
9774 defcompile X
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9775 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9776 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
9777
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9778 # 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
9779 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
9780 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9781 class A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9782 def new()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9783 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9784 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9785 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9786 defcompile A
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9787 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
9788 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9789 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
9790
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9791 # 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
9792 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
9793 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9794 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
9795 def Foo()
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9796 xxx
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9797 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9798 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9799 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9800 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
9801 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
9802 vim9script
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9803
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9804 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
9805 class B
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9806 endclass
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9807 defcompile
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9808 END
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9809 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
9810 enddef
0f2632b04cde patch 9.1.0020: Vim9: cannot compile all methods in a class
Christian Brabandt <cb@256bit.org>
parents: 34006
diff changeset
9811
34472
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9812 " 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
9813 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
9814 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
9815 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9816 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9817 def abc()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9818 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9819 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9820 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9821 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
9822
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9823 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
9824 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
9825 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9826 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9827 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
9828 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9829 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9830 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9831 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
9832 endfor
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9833 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9834
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9835 " 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
9836 " 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
9837 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
9838 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
9839 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9840 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9841 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
9842 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9843 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9844 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9845
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9846 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9847 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
9848 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
9849 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
9850 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9851
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9852 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
9853 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
9854 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
9855 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
9856 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
9857 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9858 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
9859 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9860 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9861 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
9862
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9863 " 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
9864 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
9865 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9866 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9867 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9868
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9869 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9870 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
9871 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
9872 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9873
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9874 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
9875 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
9876 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9877 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9878 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
9879
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9880 " 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
9881 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
9882 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9883 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9884 def empty()
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 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9887 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9888 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
9889
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9890 " 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
9891 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
9892 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9893 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9894 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
9895 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
9896 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9897 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9898
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9899 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9900 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
9901 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
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_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
9906 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
9907 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9908 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
9909
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9910 " 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
9911 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
9912 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9913 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9914 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
9915 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9916 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9917 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9918 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
9919 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
9920 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9921 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
9922
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9923 " 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
9924 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
9925 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9926 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9927 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
9928 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9929 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9930 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9931 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9932 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
9933 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
9934 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9935 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9936 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9937 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
9938
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9939 " 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
9940 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
9941 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9942 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9943 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
9944 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9945 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9946 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
9947 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
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 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9951 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
9952 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
9953 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9954 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9955 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9956 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
9957
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9958 " 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
9959 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
9960 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9961 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9962 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
9963 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9964 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9965 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9966 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
9967 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
9968 return true
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9969 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9970 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9971 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
9972 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
9973 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
9974 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
9975 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9976 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
9977 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
9978 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9979 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9980 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
9981
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9982 " 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
9983 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
9984 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9985 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9986 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
9987 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9988 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
9989 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
9990 return false
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9991 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9992 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9993 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
9994 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
9995 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9996 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
9997 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9998 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
9999 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
10000 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10001
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10002 " 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
10003 " 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
10004 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
10005 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
10006 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10007 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10008 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
10009 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
10010 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
10011 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10012 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
10013 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
10014 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10015 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10016
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10017 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10018 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
10019 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
10020 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
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
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10023 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
10024 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
10025 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
10026 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
10027 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
10028 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10029 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
10030 Foo()
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 " 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
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 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10038 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10039
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10040 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10041 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
10042 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
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
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10045 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
10046 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
10047 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10048 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10049 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
10050
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10051 " 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
10052 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
10053 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10054 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10055 def len()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10056 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10057 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10058 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10059 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
10060
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10061 " 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
10062 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
10063 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10064 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10065 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
10066 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
10067 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10068 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10069
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10070 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10071 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
10072 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
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()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10076 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
10077 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
10078 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10079 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
10080
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10081 " 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
10082 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
10083 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10084 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10085 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
10086 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10087 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10088 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10089 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
10090 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
10091 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10092 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
10093
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10094 " 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
10095 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
10096 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10097 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10098 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
10099 return 5
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10100 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10101 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10102 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10103 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
10104 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
10105 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10106 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10107 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10108 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
10109
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10110 " 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
10111 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
10112 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10113 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10114 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
10115 return 8
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10116 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10117 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
10118 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
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 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10122 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
10123 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
10124 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10125 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10126 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10127 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
10128
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10129 " 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
10130 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
10131 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10132 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10133 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
10134 return 10
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10135 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10136 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10137 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
10138 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
10139 return 20
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10140 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10141 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10142 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
10143 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
10144 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
10145 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
10146 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10147 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
10148 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
10149 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10150 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10151 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
10152
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10153 " 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
10154 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
10155 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10156 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10157 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
10158 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10159 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
10160 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
10161 return 123
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10162 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10163 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10164 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
10165 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
10166 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10167 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
10168 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10169 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10170 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
10171 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10172
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10173 " 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
10174 " 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
10175 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
10176 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
10177 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10178 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10179 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
10180 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
10181 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
10182 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10183 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10184
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10185 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10186 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
10187 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
10188 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
10189 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10190
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10191 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
10192 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
10193 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
10194 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
10195 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
10196 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
10197 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10198 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
10199 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10200 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10201 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
10202
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10203 " 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
10204 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
10205 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10206 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10207 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10208
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10209 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10210 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
10211 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
10212 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10213
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10214 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
10215 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
10216 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10217 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10218 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
10219
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10220 " 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
10221 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
10222 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10223 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10224 def string()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10225 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10226 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10227 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10228 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
10229
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10230 " 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
10231 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
10232 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10233 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10234 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
10235 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
10236 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10237 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10238
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10239 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10240 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
10241 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
10242 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10243
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10244 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
10245 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
10246 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
10247 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10248 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
10249
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10250 " 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
10251 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
10252 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10253 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10254 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
10255 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10256 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10257 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10258 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
10259 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
10260 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10261 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
10262
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10263 " 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
10264 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
10265 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10266 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10267 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
10268 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10269 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10270 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10271 def Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10272 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
10273 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
10274 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10275 Foo()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10276 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10277 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
10278
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10279 " 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
10280 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
10281 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10282 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10283 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
10284 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10285 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10286 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
10287 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
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 def Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10291 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
10292 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
10293 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10294 Bar()
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10295 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10296 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
10297
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10298 " 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
10299 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
10300 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10301 class A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10302 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
10303 return 'A'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10304 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10305 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10306 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
10307 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
10308 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10309 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10310 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10311 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
10312 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
10313 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
10314 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
10315 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10316 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
10317 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
10318 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10319 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10320 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
10321
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10322 " 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
10323 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
10324 vim9script
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10325 interface A
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10326 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
10327 endinterface
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10328 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
10329 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
10330 return 'B'
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10331 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10332 endclass
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10333 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
10334 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
10335 enddef
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10336 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
10337 Foo(b)
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10338 END
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10339 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
10340 endfunc
5c1a025192ed patch 9.1.0148: Vim9: can't call internal methods with objects
Christian Brabandt <cb@256bit.org>
parents: 34344
diff changeset
10341
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
10342 " 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
10343 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
10344 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
10345 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
10346 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
10347 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
10348 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
10349 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
10350 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
10351 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
10352
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
10353 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
10354 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
10355 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
10356 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
10357 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
10358 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
10359 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
10360
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
10361 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
10362 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
10363
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
10364 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
10365 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
10366 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
10367 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
10368 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
10369 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
10370
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
10371 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
10372
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
10373 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
10374 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
10375 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
10376 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
10377 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
10378 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
10379
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
10380 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
10381 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
10382 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
10383 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
10384 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
10385
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
10386 # 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
10387 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
10388 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
10389 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
10390 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
10391 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
10392 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
10393
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 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
10395 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
10396 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
10397 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
10398 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
10399 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
10400 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
10401 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
10402
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10403 " 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
10404 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
10405 # 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
10406 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
10407 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10408 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
10409 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
10410 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
10411 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
10412 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
10413 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10414 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10415 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10416 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10417
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10418 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
10419 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
10420 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
10421 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10422 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
10423
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10424 # 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
10425 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
10426 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10427 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
10428 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
10429 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
10430 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
10431 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
10432 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10433 Fn()
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10434 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10435 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10436
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10437 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
10438 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
10439 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
10440 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
10441 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10442 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
10443 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10444
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10445 " 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
10446 def Test_class_object_refcount()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10447 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10448 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10449 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10450 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10451 var a: A = A.new()
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10452 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10453 assert_equal(1, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10454 var b = a
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10455 assert_equal(2, test_refcount(A))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10456 assert_equal(2, test_refcount(a))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10457 assert_equal(2, test_refcount(b))
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10458 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10459 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10460 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10461
34618
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10462 " 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
10463 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
10464 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
10465 vim9script
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10466 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
10467 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
10468 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
10469 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
10470 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
10471 }
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10472 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
10473 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10474 endclass
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 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
10477 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
10478 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
10479 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
10480 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
10481 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10482 endclass
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10483
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10484 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
10485 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
10486 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
10487 END
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10488 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
10489 enddef
7ff3c277377f patch 9.1.0198: Vim9: compound operators broken for lambdas in an object
Christian Brabandt <cb@256bit.org>
parents: 34508
diff changeset
10490
34676
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10491 " 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
10492 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
10493 var lines =<< trim END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10494 vim9script
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10495 class A
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10496 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
10497 var n: number
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10498 endclass
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10499 defcompile
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10500 assert_equal(10, A.obj1.n)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10501 END
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10502 v9.CheckScriptSuccess(lines)
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10503 enddef
5b25ec43f208 patch 9.1.0219: Vim9: No enum support
Christian Brabandt <cb@256bit.org>
parents: 34618
diff changeset
10504
34748
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10505 " 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
10506 " 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
10507 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
10508 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
10509 vim9script
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10510
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10511 class DictKeyClass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10512 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
10513 def _GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10514 _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
10515 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10516 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
10517 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
10518 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10519 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10520
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10521 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
10522 def F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10523 this._GenerateKey()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10524 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10525 endclass
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10526
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10527 C.new().F()
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10528 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
10529 END
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10530 v9.CheckScriptSuccess(lines)
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10531 enddef
529709e74c11 patch 9.1.0252: Vim9: segfault with static in super class
Christian Brabandt <cb@256bit.org>
parents: 34676
diff changeset
10532
34769
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10533 " 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
10534 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
10535 # 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
10536 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
10537 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10538 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
10539 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
10540 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10541 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
10542 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10543 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
10544
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10545 # 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
10546 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
10547 vim9script
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10548 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
10549 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
10550 endclass
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10551 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
10552 END
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10553 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
10554 enddef
d4fb6ea26ae4 patch 9.1.0261: Vim9: protected class and funcrefs accessible outside the class
Christian Brabandt <cb@256bit.org>
parents: 34759
diff changeset
10555
34773
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10556 " 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
10557 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
10558 # 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
10559 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
10560 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10561 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
10562 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
10563 # 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
10564 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
10565 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10566 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10567 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
10568 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
10569 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10570 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
10571
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10572 # 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
10573 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
10574 vim9script
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10575 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
10576 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
10577 # 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
10578 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
10579 }
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10580 endclass
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10581 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
10582 END
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10583 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
10584 enddef
af48c532bd88 patch 9.1.0263: Vim9: Problem with lambda blocks in enums and classes
Christian Brabandt <cb@256bit.org>
parents: 34769
diff changeset
10585
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
10586 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker