annotate src/testdir/test_vim9_class.vim @ 33568:4db948057fa6 v9.0.2029

patch 9.0.2029: Vim9: no support for partials using call() Commit: https://github.com/vim/vim/commit/1ace49fb98fa93e2fcff421a5f7da1aa41c512ed Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Oct 15 09:53:41 2023 +0200 patch 9.0.2029: Vim9: no support for partials using call() Problem: Vim9: no support for partials using call() Solution: Add support closes: #13341 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 15 Oct 2023 10:00:05 +0200
parents 86dbcbb94fdb
children c470d4fd5eba
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
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
38 # Only the completed 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
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
70 # Use "this" without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
71 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
72 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
73 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
74 this
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
75 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
76 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
77 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
78
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
79 # Use "this." without any member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
80 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
81 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
82 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
83 this.
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
84 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
85 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
86 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this.', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
87
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
88 # Space between "this" and ".<variable>"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
89 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
90 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
91 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
92 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
93 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
94 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
95 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this .count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
96
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
97 # Space between "this." and the member variable name
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
98 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
99 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
100 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
101 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
102 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
103 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
104 v9.CheckSourceFailure(lines, 'E1317: Invalid object variable declaration: this. count', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
105
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
106 # Use "that" instead of "this"
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
107 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
108 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
109 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
110 this.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
111 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
112 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
113 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
114 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
115
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
116 # Member variable without a type or initialization
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
117 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
118 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
119 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
120 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
121 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
122 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
123 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
124
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
125 # Use a non-existing member variable in new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
126 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
127 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
128 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
129 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
130 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
131 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
132 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
133 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
134 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
135 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "Something": state', 1)
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
136
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
137 # Space before ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
138 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
139 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
140 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
141 this.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
142 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
143 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
144 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
145
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
146 # No space after ":" in a member variable declaration
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
147 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
148 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
149 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
150 this.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
151 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
152 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
153 v9.CheckSourceFailure(lines, "E1069: White space required after ':'", 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
154
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
155 # 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
156 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
157 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
158 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
159 # 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
160 #{
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
161 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
162 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
163 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
164
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
165 # 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
166 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
167 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
168 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
169 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
170 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
171 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
172 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
173 v9.CheckSourceFailure(lines, 'E1319: Using a class as a Number', 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
174
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
175 # 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
176 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
177 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
178 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
179 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
180 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
181 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
182 endif
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
183 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
184 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
185
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
186 # 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
187 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
188 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
189 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
190 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
191 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
192 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
193 v9.CheckSourceFailure(lines, 'E1321: Using a class as a Float', 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
194
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
195 # 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
196 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
197 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
198 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
199 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
200 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
201 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
202 END
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 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
204
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
205 # 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
206 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
207 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
208 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
209 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
210 :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
211 END
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 v9.CheckSourceFailure(lines, 'E1323: Using a class as a String', 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
213
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
214 # 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
215 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
216 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
217 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
218 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
219 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
220 :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
221 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
222 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
223
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
224 # 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
225 # 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
226 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
227 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
228
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
229 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
230 this.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
231 this.col: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
232
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
233 # 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
234 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
235 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
236 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
237 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
238
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
239 # 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
240 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
241 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
242 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
243
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
244 # 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
245 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
246
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
247 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
248 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
249 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
250 assert_equal('object<TextPosition>', typename(pos))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
251 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
252 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
253
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
254 # 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
255 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
256 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
257 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
258 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
259 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
260 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
261 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
262 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
263 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
264 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
265 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
266
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
267 # 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
268 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
269 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
270 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
271 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
272 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
273 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
274 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
275 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
276 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
277 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
278 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
279
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
280 # 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
281 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
282 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
283 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
284 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
285 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
286 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
287 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
288 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
289 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
290 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
291
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
292 # 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
293 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
294 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
295 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
296 this.y = {
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
297 X: 1
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
298 }
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
299 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
300 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
301 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
302 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
303 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
304
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
305 " 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
306 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
307 # 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
308 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
309 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
310 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
311 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
312 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
313 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
314 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
315 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
316
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
317 # 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
318 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
319 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
320 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
321 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
322 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
323 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
324 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
325 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
326
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
327 # Using the "public" keyword when defining an object private method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
328 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
329 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
330 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
331 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
332 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
333 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
334 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
335 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
336
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
337 # Using the "public" keyword when defining a class private method
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
338 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
339 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
340 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
341 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
342 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
343 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
344 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
345 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
346
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
347 # 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
348 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
349 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
350 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
351 def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
352 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
353 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
354 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
355 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
356
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
357 # 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
358 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
359 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
360 class A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
361 static def
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
362 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
363 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
364 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
365 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
366 enddef
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
367
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
368 def Test_class_defined_twice()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
369 # class defined twice should fail
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
370 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
371 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
372 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
373 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
374 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
375 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
376 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
377 v9.CheckSourceFailure(lines, 'E1041: Redefining script item: "There"', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
378
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
379 # one class, reload same script twice is OK
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
380 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
381 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
382 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
383 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
384 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
385 writefile(lines, 'XclassTwice.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
386 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
387 source XclassTwice.vim
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
388 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
389
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
390 def Test_returning_null_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
391 # this was causing an internal error
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
392 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
393 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
394
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
395 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
396 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
397 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
398 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
399 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
400
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
401 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
402 echo buffers.Current()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
403 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
404 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
405 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
406
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
407 def Test_using_null_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
408 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
409 @_ = 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
410 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
411 v9.CheckDefExecAndScriptFailure(lines, ['E715: Dictionary required', 'E1363: Incomplete type'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
412 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
413
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
414 def Test_class_interface_wrong_end()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
415 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
416 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
417 abstract class SomeName
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
418 this.member = 'text'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
419 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
420 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
421 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
422
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
423 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
424 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
425 export interface AnotherName
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
426 this.member: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
427 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
428 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
429 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
430 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
431
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
432 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
433 # Use an uninitialized object in script context
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
434 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
435 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
436
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
437 class State
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
438 this.value = 'xyz'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
439 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
440
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
441 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
442 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
443 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
444 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
445 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 9)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
446
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
447 # Use an uninitialized object from a def function
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
448 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
449 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
450
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
451 class Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
452 this.id: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
453 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
454 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
455 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
456 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
457
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
458 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
459 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
460 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
461 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
462 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
463 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
464 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
465
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
466 # 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
467 # object method.
32670
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
471 class Background
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
472 this.background = 'dark'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
473 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
474
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
475 class Colorscheme
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
476 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
477
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
478 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
479 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
480 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
481 endclass
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 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
484 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
485 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
486 v9.CheckSourceFailure(lines, 'E1360: Using a null object', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
487
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
488 # 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
489 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
490 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
491
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
492 class Class
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
493 this.id: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
494 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
495 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
496 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
497 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
498
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
499 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
500 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
501 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
502 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
503 Func()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
504 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
505 v9.CheckSourceFailure(lines, 'E1363: Incomplete type', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
506 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
507
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
508 " 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
509 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
510 var lines =<< trim END
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
511 vim9script
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
512
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
513 var nullo = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
514 def F(): any
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
515 return nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
516 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
517 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
518
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
519 var o0 = F()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
520 assert_true(o0 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
521 assert_true(o0 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
522
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
523 var o1: any = nullo
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
524 assert_true(o1 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
525 assert_true(o1 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
526
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
527 def G()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
528 var x = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
529 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
530
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
531 class C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
532 endclass
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
533 var o2: C
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
534 assert_true(o2 == null_object)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
535 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
536
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
537 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
538 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
539
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
540 o2 = C.new()
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
541 assert_true(o2 != null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
542
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
543 o2 = null_object
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
544 assert_true(o2 == null)
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
545 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
546 v9.CheckSourceSuccess(lines)
33008
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
547 enddef
ba1b40b520e8 patch 9.0.1796: Vim9 problems with null_objects
Christian Brabandt <cb@256bit.org>
parents: 32972
diff changeset
548
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
549 " Test for object member initialization and disassembly
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
550 def Test_class_member_initializer()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
551 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
552 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
553
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
554 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
555 this.lnum: 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
556 this.col: 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
557
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
558 # 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
559 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
560 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
561 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
562 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
563
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
564 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
565 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
566 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
567
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
568 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
569 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
570 '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
571 '\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
572 '\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
573 '\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
574 '\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
575 '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
576 '\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
577 '\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
578 '\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
579 '\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
580 '\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
581 instr)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
582 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
583 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
584 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
585
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
586 def Test_member_any_used_as_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
587 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
588 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
589
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
590 class Inner
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
591 this.value: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
592 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
593
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
594 class Outer
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
595 this.inner: any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
596 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
597
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
598 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
599 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
600 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
601
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
602 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
603 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
604 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
605 assert_equal(1, inner_obj.value)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
606 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
607 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
608
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
609 # Try modifying a private 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
610 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
611 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
612
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
613 class Inner
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
614 this._value: string = ''
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
615 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
616
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
617 class Outer
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
618 this.inner: any
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
619 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
620
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
621 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
622 outer.inner._value = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
623 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
624
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
625 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
626 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
627 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
628 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
629 v9.CheckSourceFailure(lines, 'E1333: Cannot access private 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
630
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
631 # 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
632 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
633 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
634
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
635 class Inner
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
636 this.value: string = ''
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
637 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
638
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
639 class Outer
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
640 this.inner: any
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
641 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
642
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
643 def F(outer: Outer)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
644 outer.inner.someval = 'b'
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
645 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
646
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
647 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
648 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
649 F(outer_obj)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
650 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
651 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "Inner": someval', 1)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
652 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
653
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
654 " 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
655 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
656 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
657 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
658
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
659 class Inner
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
660 public this.value: number = 0
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
661 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
662
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
663 class Outer
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
664 this.inner: Inner
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
665 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
666
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
667 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
668 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
669 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
670
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
671 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
672 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
673 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
674 F(outer)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
675 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
676 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
677
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
678 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
679
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
680 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
681 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
682 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
683 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
684 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
685 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
686
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
687 # 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
688 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
689 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
690
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
691 class Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
692 this.value: number = 0
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
693 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
694
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
695 class Outer
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
696 this.inner: Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
697 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
698
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
699 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
700 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
701 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
702
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
703 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
704 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
705 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
706 F(outer)
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
707 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
708 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
709
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
710 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
711 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
712 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
713
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
714 # 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
715 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
716 vim9script
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
717
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
718 class Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
719 this.value: number = 0
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
720 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
721
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
722 class Outer
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
723 this.inner: Inner
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
724 endclass
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
725
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
726 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
727 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
728 enddef
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
729
ab0ecf1bd6b5 patch 9.0.1920: Vim9: cannot write public var in nested object
Christian Brabandt <cb@256bit.org>
parents: 33297
diff changeset
730 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
731 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
732 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
733 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
734 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
735 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
736 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
737
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
738 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
739 # Use "+=" to assign to a object variable
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
740 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
741 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
742
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
743 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
744 public this.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
745
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
746 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
747 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
748 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
749 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
750
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
751 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
752 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
753 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
754
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
755 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
756 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
757 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
758
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
759 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
760 assert_equal(23, f.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
761 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
762 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
763 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
764
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
765 def Test_list_of_objects()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
766 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
767 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
768
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
769 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
770 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
771 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
772 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
773
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
774 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
775 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
776 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
777 endfor
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
778 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
779
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
780 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
781 ProcessList(l)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
782 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
783 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
784 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
785
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
786 def Test_expr_after_using_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
787 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
788 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
789
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
790 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
791 this.label: string = ''
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
792 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
793
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
794 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
795 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
796 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
797 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
798 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
799
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
800 Foo()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
801 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
802 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
803 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
804
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
805 def Test_class_default_new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
806 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
807 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
808
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
809 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
810 this.lnum: 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
811 this.col: 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
812 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
813
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
814 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
815 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
816 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
817
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
818 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
819 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
820 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
821
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
822 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
823 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
824 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
825
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
826 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
827 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
828 assert_equal(33, pos.col)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
829 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
830 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
831
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
832 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
833 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
834 class Person
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.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
836 this.age: number = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
837 this.education: string = "unknown"
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 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
840 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
841 endclass
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 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
844 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
845 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
846 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
847
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
848 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
849 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
850 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
851 assert_equal("none", chris.education)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
852 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
853 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
854
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
855 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
856 vim9script
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 Person
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
858 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
859 this.age: number = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
860 this.education: string = "unknown"
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 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
863 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
864 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
865
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
866 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
867 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
868 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
869
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
870 # 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
871 # method.
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
872 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
873 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
874 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
875 this.val: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
876 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
877 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
878 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
879 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
880 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
881 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
882
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
883 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
884 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
885 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
886
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
887 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
888 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
889 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
890 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
891 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
892 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
893 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
894 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
895
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
896 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
897 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
898 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
899 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
900 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
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 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
903 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
904 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
905 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
906 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
907 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
908 enddef
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 Check()
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
911 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
912 v9.CheckSourceSuccess(lines)
32822
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
913
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
914 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
915 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
916
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
917 class C
7c9124711f99 patch 9.0.1948: Vim9: object variable "this." should only be used in constructor
Christian Brabandt <cb@256bit.org>
parents: 33372
diff changeset
918 this.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
919 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
920 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
921 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
922 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
923
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
924 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
925 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
926 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
927 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
928 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
929 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
930 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
931
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
932 Check()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
933 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
934 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
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 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
937 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
938
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
939 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
940 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
941 this.num: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
942 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
943 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
944 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
945
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
946 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
947 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
948 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
949 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
950 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
951 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
952 enddef
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 Check()
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, '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
957
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
958 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
959 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
960
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
961 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
962 this.str: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
963 def new(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
964 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
965 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
966
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
967 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
968 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
969 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
970 catch
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
971 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
972 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
973 enddef
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 Check()
33326
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
976 END
4e531adb3fac patch 9.0.1928: Vim9: constructor type checking bug
Christian Brabandt <cb@256bit.org>
parents: 33322
diff changeset
977 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
978
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
979 # 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
980 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
981 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
982 class A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
983 this.val = 10
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
984 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
985 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
986 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
987 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
988 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
989
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
990 # 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
991 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
992 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
993 class A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
994 this.val = 10
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
995 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
996 enddef
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
997 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
998 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
999 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
1000 enddef
b3a42579bb3f patch 9.0.1724: vim9class constructor argument type checking bug
Christian Brabandt <cb@256bit.org>
parents: 32812
diff changeset
1001
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1002 def Test_class_object_member_inits()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1003 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
1004 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1005 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1006 this.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
1007 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1008 this.addcol: 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
1009 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1010
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1011 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
1012 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
1013 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
1014 assert_equal(2, pos.addcol)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1015 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1016 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1017
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1018 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
1019 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1020 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1021 this.lnum
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1022 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1023 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1024 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 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1026
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1027 # 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
1028 # object creation and not when defining the class.
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1029 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
1030 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1031
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1032 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
1033 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
1034 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
1035 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
1036 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1037
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1038 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1039 this.str1 = Init()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1040 this.str2: string = Init()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1041 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1042 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1043
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1044 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
1045 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
1046 assert_equal(init_count, 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1047 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1048 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
1049
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1050 # 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
1051 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
1052 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
1053 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
1054 this.value = init_val
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1055 endclass
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
1056 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
1057 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1058 v9.CheckSourceFailure(lines, '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
1059
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1060 # 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
1061 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
1062 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1063 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
1064 this.value: void
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1065 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
1066 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1067 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
1068 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1069
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1070 " 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
1071 def Test_instance_variable_access()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1072 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
1073 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1074 class Triple
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1075 this._one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1076 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1077 public this.three = 3
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1078
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1079 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
1080 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
1081 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1082 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1083
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1084 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
1085 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
1086 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
1087 assert_equal(3, trip.three)
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1088 assert_fails('echo trip._one', 'E1333: Cannot access private variable "_one" in class "Triple"')
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1089
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1090 assert_fails('trip._one = 11', 'E1333: Cannot access private 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
1091 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
1092 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
1093 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
1094
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1095 assert_fails('trip.four = 4', 'E1326: Variable not found on object "Triple": four')
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1096 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1097 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1098
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
1099 # 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
1100 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
1101 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
1102 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
1103 public this._val = 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
1104 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
1105 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1106 v9.CheckSourceFailure(lines, 'E1332: Public variable name cannot start with underscore: public this._val = 10', 3)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1107
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1108 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
1109 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1110
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1111 class MyCar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1112 this.make: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1113 this.age = 5
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1114
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1115 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
1116 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
1117 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1118
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1119 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
1120 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
1121 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1122 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
1123 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
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 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1126
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1127 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
1128 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
1129
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1130 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
1131 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
1132
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 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
1134 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
1135
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1136 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
1137 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
1138 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
1139 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1140 CheckCar()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1141 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1142 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1143
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1144 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
1145 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1146
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1147 class MyCar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1148 this.make: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1149
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1150 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
1151 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
1152 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1153 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1154
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1155 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
1156 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
1157 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1158 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
1159
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1160 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
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1163 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
1164 this.x: list<number> = []
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1165
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1166 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
1167 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
1168 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
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 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
1173 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
1174 .x
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1175 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
1176 .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
1177 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
1178 .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
1179 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
1180 .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
1181 .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
1182 .x
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1183 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1184 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
1185
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1186 # 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
1187 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
1188 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
1189 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
1190 pub this.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
1191 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
1192 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1193 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: pub this.val = 1', 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
1194
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1195 # Test for "public" keyword must be followed by "this" or "static".
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1196 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
1197 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
1198 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
1199 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
1200 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
1201 END
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 v9.CheckSourceFailure(lines, 'E1331: Public must be followed by "this" or "static"', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1203
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1204 # 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
1205 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1206 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1207 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1208 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1209 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1210 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1211 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1212 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
1213
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1214 # 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
1215 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
1216 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1217 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1218 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1219 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1220 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1221 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1222 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
1223
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1224 # 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
1225 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
1226 vim9script
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1227 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1228 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1229 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1230 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1231 A.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1232 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1233 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1234 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1235 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
1236
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1237 # 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
1238 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1239 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1240 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1241 public this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1242 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1243 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1244 var i = A.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1245 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1246 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1247 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1248 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
1249
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
1250 # 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
1251 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
1252 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1253 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1254 this.ro_obj_var = 10
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1255 public this.rw_obj_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
1256 this._priv_obj_var = 30
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1257 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1258
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1259 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
1260 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
1261 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
1262 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
1263 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
1264 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
1265 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
1266 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
1267 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
1268 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1269 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1270
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1271 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
1272 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1273 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1274 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1275 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1276
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1277 " 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
1278 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
1279 # 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
1280 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1281 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1282 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1283 stat this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1284 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1285 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1286 v9.CheckSourceFailure(lines, 'E1065: Command cannot be shortened: stat this.val = 1', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1287
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1288 # Test for "static" cannot be followed by "this".
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1289 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1290 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1291 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1292 static this.val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1293 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1294 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1295 v9.CheckSourceFailure(lines, 'E1368: Static cannot be followed by "this" in a variable name', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1296
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1297 # 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
1298 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1299 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1300 class Something
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1301 static public val = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1302 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1303 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1304 v9.CheckSourceFailure(lines, 'E1022: Type or initialization required', 3)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1305
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1306 # 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
1307 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
1308 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1309 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1310 static ro_class_var = 40
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1311 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1312
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1313 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
1314 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
1315 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
1316 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1317 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1318
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1319 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
1320 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
1321 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1322 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
1323
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1324 # A private class variable cannot be accessed from a child class
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1325 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
1326 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1327 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1328 static _priv_class_var = 60
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1329 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1330
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1331 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
1332 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
1333 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
1334 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1335 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1336
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1337 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
1338 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
1339 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1340 v9.CheckSourceFailure(lines, 'E1333: Cannot access private 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
1341
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1342 # A private 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
1343 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
1344 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1345 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1346 static _priv_class_var = 60
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1347 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1348
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1349 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
1350 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
1351 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
1352 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1353 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1354
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1355 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
1356 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
1357 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1358 v9.CheckSourceFailure(lines, 'E1333: Cannot access private 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
1359
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1360 # 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
1361 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
1362 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1363 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1364 static ro_class_var = 10
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1365 public static 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
1366 static _priv_class_var = 30
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1367 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1368
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1369 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
1370 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
1371 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
1372 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
1373 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
1374 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
1375 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
1376 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
1377 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
1378 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1379 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1380
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1381 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
1382 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
1383 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
1384 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
1385 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
1386 b.Foo()
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1387 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1388 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1389 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1390
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1391 def Test_class_object_compare()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1392 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
1393 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1394 class Item
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1395 this.nr = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1396 this.name = 'xx'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1397 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1398 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1399
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1400 # used at the script level and in a compiled function
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1401 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
1402 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
1403 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
1404 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
1405 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
1406 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
1407 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
1408 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
1409 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
1410
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1411 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
1412 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
1413 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
1414 assert_notequal(i1, io2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1415 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1416
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1417 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
1418 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
1419 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1420
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1421 for op in ['>', '>=', '<', '<=', '=~', '!~']
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1422 var op_lines = [
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1423 'var i1 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1424 'var i2 = Item.new()',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1425 'echo i1 ' .. op .. ' i2',
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1426 ]
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1427 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
1428 v9.CheckSourceFailure(class_lines
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1429 + ['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
1430 endfor
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1431 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1432
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1433 def Test_object_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1434 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
1435 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1436
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1437 class One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1438 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1439 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1440 class Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1441 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1442 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1443 class TwoMore extends Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1444 this.more = 9
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1445 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1446
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1447 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
1448 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
1449 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
1450 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
1451
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1452 t = m
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1453 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1454 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1455
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1456 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
1457 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1458
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1459 class One
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1460 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1461 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1462 class Two
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1463 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1464 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1465
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1466 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
1467 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1468 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
1469
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1470 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
1471 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1472
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1473 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
1474 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
1475 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1476 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
1477 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1478 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
1479 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
1480 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1481 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1482
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1483 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
1484 assert_equal(5, o.GetMember())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1485 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1486 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1487
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1488 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
1489 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1490
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1491 class Num
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1492 this.n: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1493 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1494
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1495 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
1496 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
1497 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
1498 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1499 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1500
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1501 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
1502 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
1503
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1504 echo Fn(Num.new(4))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1505 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1506 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1507 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1508
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1509 def Test_class_member()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1510 # check access rules
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1511 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
1512 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1513 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
1514 this.lnum = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1515 this.col = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1516 static counter = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1517 static _secret = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1518 public static anybody = 42
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1519
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1520 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
1521 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
1522 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1523 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1524
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1525 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
1526 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
1527 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
1528 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
1529
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1530 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
1531 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
1532 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1533 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
1534
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1535 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
1536 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
1537 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
1538
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1539 assert_fails('echo TextPos._secret', 'E1333: Cannot access private variable "_secret" in class "TextPos"')
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
1540 assert_fails('TextPos._secret = 8', 'E1333: Cannot access private 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
1541
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1542 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
1543 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
1544 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
1545 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
1546 assert_equal(17, TextPos.anybody)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1547 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1548 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1549
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1550 # example in the help
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1551 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
1552 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1553 class OtherThing
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1554 this.size: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1555 static totalSize: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1556
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 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
1558 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
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 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
1562 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
1563 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
1564 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
1565 assert_equal(10, OtherThing.totalSize)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1566 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1567 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1568
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1569 # using static class member twice
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1570 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
1571 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1572
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1573 class HTML
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1574 static author: string = 'John Doe'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1575
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1576 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
1577 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
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 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1580
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1581 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
1582 assert_equal('some text', HTML.MacroSubstitute('some text'))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1583 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1584 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1585
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1586 # access private member in lambda
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1587 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
1588 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1589
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1590 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
1591 this._x: number = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1592
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1593 def 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
1594 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
1595 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
1596 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1597 endclass
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 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
1600 assert_equal(5, foo.Add(5))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1601 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1602 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1603
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1604 # access private member in lambda body
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1605 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
1606 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1607
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1608 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
1609 this._x: number = 6
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1610
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1611 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
1612 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
1613 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
1614 }
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1615 Lam()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1616 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
1617 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1618 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1619
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1620 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
1621 assert_equal(13, foo.Add(7))
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1622 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1623 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1624
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1625 # check shadowing
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1626 lines =<< trim END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1627 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1628
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1629 class Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1630 static 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
1631 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
1632 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
1633 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1634 endclass
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 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
1637 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
1638 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1639 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
1640
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
1641 # 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
1642 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
1643 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1644
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1645 class Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1646 static 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
1647 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
1648 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
1649 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
1650 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1651 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1652
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1653 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
1654 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
1655 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1656 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
1657
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1658 # 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
1659 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
1660 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
1661 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
1662 this.val: xxx
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1663 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
1664 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1665 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
1666
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1667 # 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
1668 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1669 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1670 class 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
1671 public this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1672 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1673
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1674 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
1675 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
1676 obj.val = ""
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1677 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1678 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1679 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1680 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
1681
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1682 # 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
1683 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1684 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1685 class 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
1686 this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1687 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1688
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1689 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
1690 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
1691 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
1692 enddef
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1693 F()
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1694 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1695 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
1696
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1697 # 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
1698 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1699 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1700 class 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
1701 public this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1702 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1703
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1704 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1705 obj.val = ""
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1706 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
1707 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
1708
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1709 # 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
1710 lines =<< trim END
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1711 vim9script
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1712 class 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
1713 this.val: string
33090
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1714 endclass
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1715
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1716 var obj: A
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1717 echo obj.val
461541d860ac patch 9.0.1830: Vim9: crash when accessing a null object
Christian Brabandt <cb@256bit.org>
parents: 33088
diff changeset
1718 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1719 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
1720
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
1721 # 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
1722 # 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
1723 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
1724 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
1725 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
1726 this.val: 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
1727 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
1728 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1729 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
1730 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
1731 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
1732 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
1733 this.val: 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
1734 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
1735 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1736 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
1737
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 # 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
1739 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
1740 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
1741 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
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 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
1744 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
1745 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
1746 v9.CheckSourceFailure(lines, 'E1337: Class variable "bar" not found in class "A"', 5)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1747 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1748
33498
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1749 " 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
1750 " 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
1751 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
1752 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
1753 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1754
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1755 class Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1756 this._v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1757 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1758
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1759 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
1760 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1761
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1762 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
1763 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
1764 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1765 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_v1" in class "Base"', 11)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1766 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1767 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1768
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1769 class Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1770 this._v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1771 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1772
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1773 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
1774 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1775
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1776 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1777 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
1778 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
1779 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1780 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1781 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1782 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_v1" in class "Base"', 2)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1783 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1784 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1785
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1786 class Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1787 this.v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1788 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1789
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1790 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
1791 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1792
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1793 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
1794 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1795 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1796 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
1797 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1798 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1799
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1800 class Base
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1801 this.v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1802 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1803
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1804 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
1805 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1806
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1807 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1808 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
1809 o.v1 = []
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1810 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1811 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1812 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1813
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1814 # Attempt to read a private variable that is in the middle
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1815 # 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
1816 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
1817 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1818 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1819
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1820 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1821 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1822
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1823 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
1824 this._v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1825 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1826
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1827 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
1828 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1829
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1830 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1831 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
1832 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
1833 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1834 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1835 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1836 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_v1" in class "Base"', 2)
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 # Attempt to read a private variable that is at the start
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1839 # 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
1840 lines =<< trim END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1841 vim9script
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1842
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1843 class Base0
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1844 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1845
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1846 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
1847 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1848
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1849 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
1850 this._v1: list<list<number>>
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1851 endclass
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1852
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1853 def F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1854 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
1855 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
1856 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1857 F()
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1858 END
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1859 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_v1" in class "Child"', 2)
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1860 enddef
bff8ac203a22 patch 9.0.1999: Vim9: some error messages can be improved
Christian Brabandt <cb@256bit.org>
parents: 33471
diff changeset
1861
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1862 func Test_class_garbagecollect()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1863 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
1864 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1865
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1866 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1867 this.p = [2, 3]
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1868 static pl = ['a', 'b']
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1869 static pd = {a: 'a', b: 'b'}
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1870 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1871
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1872 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
1873 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
1874 echo Point.pl Point.pd
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1875 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1876 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1877
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1878 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
1879 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1880
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1881 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
1882 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1883
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1884 class Widget
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1885 this.view: View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1886 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1887
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1888 class MyView implements View
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1889 this.widget: Widget
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1890
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1891 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
1892 # this will result in a circular reference to this object
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1893 this.widget = Widget.new(this)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1894 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1895 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1896
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1897 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
1898
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1899 # 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
1900 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
1901 test_garbagecollect_now()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1902 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1903 call v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1904 endfunc
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1905
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1906 " Test interface garbage collection
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1907 func Test_interface_garbagecollect()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1908 let lines =<< trim END
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1909 vim9script
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1910
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1911 interface I
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1912 this.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
1913
33167
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1914 def ObjFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1915 endinterface
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1916
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1917 class A implements I
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1918 static ro_class_var: number = 10
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1919 public static rw_class_var: number = 20
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1920 static _priv_class_var: number = 30
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1921 this.ro_obj_var: number = 40
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1922 this._priv_obj_var: number = 60
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1923
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1924 static def _ClassBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1925 return _priv_class_var
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1926 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1927
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1928 static def ClassFoo(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1929 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
1930 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1931
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1932 def _ObjBar(): number
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1933 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
1934 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1935
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1936 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
1937 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
1938 enddef
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1939 endclass
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1940
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1941 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
1942 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
1943 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
1944 test_garbagecollect_now()
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1945 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
1946 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
1947 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1948 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
1949 endfunc
13258b342d38 patch 9.0.1865: Vim9: garbage collection may cause crash
Christian Brabandt <cb@256bit.org>
parents: 33160
diff changeset
1950
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1951 def Test_class_method()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1952 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
1953 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1954 class Value
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1955 this.value = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1956 static objects = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1957
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1958 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
1959 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
1960 ++objects
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1961 enddef
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 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
1964 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
1965 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1966 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1967
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1968 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
1969 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
1970 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
1971 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
1972 assert_equal(2, Value.GetCount())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
1973 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
1974 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
1975
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
1976 # 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
1977 # 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
1978 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
1979 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
1980 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
1981 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
1982 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
1983 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
1984 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
1985 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
1986 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
1987
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1988 # 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
1989 # name prefix.
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1990 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
1991 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1992 class A
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1993 static myList: list<number> = [1]
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1994 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
1995 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
1996 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1997 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
1998 Foo(2)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
1999 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2000 def Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2001 Foo(3)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2002 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2003 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2004 A.Bar()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2005 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
2006 a.Baz()
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2007 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
2008 END
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
2009 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2010 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2011
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2012 def Test_class_defcompile()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2013 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
2014 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2015
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2016 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
2017 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
2018 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
2019 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2020 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2021
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2022 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
2023 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2024 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
2025
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2026 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
2027 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2028
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2029 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
2030 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
2031 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
2032 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2033 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2034
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2035 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
2036 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2037 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
2038
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2039 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
2040 vim9script
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 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
2043 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
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 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
2048 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2049 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
2050
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
2051 # 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
2052 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
2053 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
2054 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
2055 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2056 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
2057
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 # 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
2059 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
2060 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
2061 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
2062 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
2063 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2064 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
2065
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2066 # 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
2067 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
2068 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
2069 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
2070 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
2071 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
2072 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2073 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
2074
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2075 # 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
2076 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
2077 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
2078 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
2079 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
2080 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
2081 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
2082 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2083 v9.CheckSourceFailureList(lines, ['E1326: Variable not found on object "A": Foo', 'E475: Invalid argument: a.Foo()'])
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2084 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2085
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2086 def Test_class_object_to_string()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2087 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
2088 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2089 class TextPosition
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2090 this.lnum = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2091 this.col = 22
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2092 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2093
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2094 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
2095
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2096 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
2097 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
2098 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2099 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2100 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2101
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2102 def Test_interface_basics()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2103 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
2104 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2105 interface Something
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2106 this.ro_var: list<number>
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2107 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
2108 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2109 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2110 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2111
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2112 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
2113 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2114 static count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2115 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2116 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2117 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
2118
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2119 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
2120 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2121
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2122 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2123 this.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
2124 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
2125 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2126 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2127 # 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
2128 # 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
2129 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2130
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2131 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
2132 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2133 interface somethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2134 static count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2135 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2136 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2137 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
2138
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2139 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
2140 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2141 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2142 this.value: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2143 this.count = 7
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2144 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
2145 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2146 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2147 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
2148
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2149 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
2150 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2151 interface SomethingWrong
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2152 this.value: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2153 this.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
2154 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
2155 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
2156 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2157 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2158 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2159 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
2160
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2161 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
2162 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2163 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
2164 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
2165 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
2166 endinterface
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2167 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2168 writefile(lines, 'XdefIntf.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2169
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2170 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
2171 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2172 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
2173 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
2174 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
2175 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2176 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2177 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2178 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
2179 endtry
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2180 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2181 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2182 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2183
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2184 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
2185 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2186 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
2187 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
2188 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2189 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
2190 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2191 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2192 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2193 writefile(imported, 'XdefIntf2.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2194
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2195 lines[1] = " import './XdefIntf2.vim' as defIntf"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2196 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2197 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2198
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2199 def Test_class_implements_interface()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2200 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
2201 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2202
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2203 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2204 this.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
2205 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
2206 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2207
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2208 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2209 this.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
2210 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
2211 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
2212 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2213 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2214
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2215 interface Another
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2216 this.member: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2217 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2218
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2219 class AnotherImpl implements Some, Another
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2220 this.member = 'abc'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2221 this.count = 20
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2222 def 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
2223 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
2224 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2225 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2226 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2227 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2228
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2229 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
2230 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2231
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2232 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2233 this.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
2234 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2235
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2236 class SomeImpl implements Some implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2237 this.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
2238 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2239 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2240 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
2241
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2242 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
2243 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2244
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2245 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2246 this.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
2247 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2248
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2249 class SomeImpl implements Some, Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2250 this.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
2251 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2252 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2253 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
2254
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2255 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
2256 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2257
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2258 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2259 this.counter: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2260 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
2261 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2262
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2263 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2264 this.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
2265 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
2266 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
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 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2269 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2270 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
2271
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2272 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
2273 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2274
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2275 interface Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2276 this.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
2277 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
2278 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2279
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2280 class SomeImpl implements Some
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2281 this.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
2282 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
2283 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
2284 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2285 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2286 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2287 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
2288
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2289 # Check different order of members in class and interface works.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2290 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
2291 vim9script
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2292
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2293 interface Result
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2294 this.label: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2295 this.errpos: number
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2296 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2297
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2298 # order of members is opposite of interface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2299 class Failure implements Result
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2300 public this.lnum: number = 5
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2301 this.errpos: number = 42
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2302 this.label: string = 'label'
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2303 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2304
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2305 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
2306 var result: Result = Failure.new()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2307
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2308 assert_equal('label', result.label)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2309 assert_equal(42, result.errpos)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2310 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2311
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2312 Test()
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2313 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2314 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
2315
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2316 # 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
2317 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
2318 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
2319 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
2320 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
2321 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
2322 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
2323 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2324 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
2325
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2326 # 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
2327 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
2328 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
2329 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
2330 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
2331 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2332 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
2333
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2334 # 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
2335 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
2336 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
2337 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
2338 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
2339 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2340 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
2341
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2342 # 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
2343 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
2344 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
2345 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
2346 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
2347 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
2348 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
2349 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2350 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
2351
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2352 # 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
2353 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
2354 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
2355 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
2356 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
2357 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
2358 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2359 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
2360
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2361 # 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
2362 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2363 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2364 interface A
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2365 endinterface
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2366 class B implements A;
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2367 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
2368 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2369 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
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 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
2372 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2373
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2374 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
2375 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
2376 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2377 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
2378 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
2379 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2380 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2381 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2382 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
2383
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2384 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
2385 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2386
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2387 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
2388 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
2389 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2390 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
2391 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
2392 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2393 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2394 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2395 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
2396
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2397 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
2398 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2399
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2400 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
2401 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
2402 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2403 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
2404 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
2405 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2406 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2407 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2408 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
2409
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2410 # 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
2411 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2412 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2413
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2414 interface I1
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 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2416 this.mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2417 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2418
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2419 # 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
2420 class A implements I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2421 this.mvar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2422 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2423 public static svar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2424 public static svar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2425 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
2426 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
2427 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
2428 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
2429 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
2430 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2431 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2432
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2433 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
2434 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
2435 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
2436 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
2437 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2438 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2439
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2440 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
2441 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
2442 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
2443 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
2444 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2445 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2446
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2447 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
2448 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
2449 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2450
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2451 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2452 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2453 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2454
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2455 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
2456 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
2457 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
2458 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2459 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2460
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2461 # 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
2462 # 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
2463 lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2464 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2465
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2466 interface I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2467 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2468 this.mvar2: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2469 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2470
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2471 interface I2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2472 this.mvar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2473 this.mvar4: number
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2474 endinterface
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2475
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2476 class A implements I1
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2477 public static svar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2478 public static svar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2479 this.mvar1: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2480 this.mvar2: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2481 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
2482 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
2483 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
2484 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
2485 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
2486 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2487 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2488
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2489 class B extends A implements I2
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2490 static svar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2491 static svar4: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2492 this.mvar3: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2493 this.mvar4: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2494 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
2495 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
2496 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
2497 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
2498 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
2499 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
2500 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
2501 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2502 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2503
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2504 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
2505 public static svar5: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2506 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
2507 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
2508 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
2509 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
2510 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
2511 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
2512 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2513 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2514
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2515 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
2516 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
2517 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2518
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2519 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
2520 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
2521 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2522
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2523 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2524 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2525 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2526
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
2527 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
2528 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
2529 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
2530 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2531 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
2532
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2533 # 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
2534 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
2535 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2536 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2537 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2538 interface B
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2539 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2540 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
2541 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2542 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2543 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
2544
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2545 # 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
2546 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
2547 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2548 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2549 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2550 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
2551 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2552 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2553 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
2554
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2555 # 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
2556 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
2557 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2558 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
2559 endclass
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2560 END
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
2561 v9.CheckSourceFailure(lines, 'E1389: Missing name after implements', 2)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2562 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2563
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2564 def Test_call_interface_method()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2565 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2566 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2567 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2568 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2569 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2570
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2571 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2572 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2573 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2574 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2575 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2576
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2577 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2578 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2579 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2580
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2581 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2582 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2583 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2584 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2585 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2586 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2587
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2588 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2589 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2590 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2591 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2592 g:result ..= 'base'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2593 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2594 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2595
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2596 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2597 def Enter(): void
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2598 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2599 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2600 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2601
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2602 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2603 obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2604 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2605
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2606 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2607 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2608 assert_equal('child', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2609 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2610 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2611 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2612
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2613 # method of interface returns a value
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2614 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2615 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2616 interface Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2617 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2618 endinterface
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2619
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2620 class Child implements Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2621 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2622 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2623 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2624 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2625 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2626
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2627 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2628 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2629 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2630 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2631
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2632 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2633 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2634 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2635 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2636 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2637 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2638
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2639 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2640 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2641 class Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2642 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2643 return null_string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2644 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2645 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2646
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2647 class Child extends Base
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2648 def Enter(): string
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2649 g:result ..= 'child'
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2650 return "/resource"
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2651 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2652 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2653
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2654 def F(obj: Base)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2655 var r = obj.Enter()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2656 g:result ..= r
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2657 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2658
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2659 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2660 F(Child.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2661 assert_equal('child/resource', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2662 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2663 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2664 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2665
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2666 # No class that implements the interface.
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2667 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
2668 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2669
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2670 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
2671 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
2672 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
2673 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2674
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2675 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
2676 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
2677 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2678
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2679 defcompile
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2680 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2681 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2682 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2683
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2684 def Test_class_used_as_type()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2685 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
2686 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2687
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2688 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2689 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2690 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2691 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2692
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2693 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
2694 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
2695 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
2696 assert_equal(33, p.y)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2697 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2698 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2699
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2700 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
2701 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2702
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2703 interface HasX
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2704 this.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
2705 endinterface
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2706
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2707 class Point implements HasX
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2708 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2709 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2710 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2711
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2712 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
2713 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
2714 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
2715 assert_equal(2, hx.x)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2716 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2717 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2718
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2719 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
2720 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2721
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2722 class Point
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2723 this.x = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2724 this.y = 0
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2725 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2726
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2727 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
2728 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
2729 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2730 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
2731 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2732
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2733 def Test_class_extends()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2734 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
2735 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2736 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2737 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2738 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
2739 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
2740 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2741 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2742 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
2743 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2744 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
2745 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
2746 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2747 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2748 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
2749 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
2750 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
2751 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
2752 assert_equal(3, o.GetTotal())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2753 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2754 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2755
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2756 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
2757 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2758 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2759 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2760 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2761 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
2762 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2763 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2764 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
2765 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
2766 assert_equal(44, o.two)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2767 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2768 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2769
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2770 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
2771 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2772 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2773 this.one = 1
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2774 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2775 class Child extends Base 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
2776 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2777 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2778 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2779 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
2780
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2781 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
2782 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2783 class Child extends BaseClass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2784 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2785 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2786 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2787 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
2788
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2789 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
2790 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2791 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
2792 class Child extends SomeVar
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2793 this.two = 2
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2794 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2795 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2796 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
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 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
2799 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2800 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2801 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2802 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
2803 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
2804 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2805 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2806
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2807 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
2808 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2809 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
2810 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
2811 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2812 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2813
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2814 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
2815 assert_equal('John: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2816 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2817 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2818
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2819 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
2820 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2821 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2822 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2823 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
2824 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
2825 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2826 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
2827 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
2828 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2829 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2830 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2831 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
2832
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2833 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
2834 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2835 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2836 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2837 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
2838 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
2839 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2840 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2841 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
2842 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
2843 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2844 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
2845
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2846 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
2847 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2848 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2849 this.name: string
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2850 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
2851 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
2852 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2853 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2854
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 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
2856 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
2857 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
2858 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2859 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
2860 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2861 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
2862
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2863 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
2864 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2865 class Child
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2866 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2867 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
2868 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
2869 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2870 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2871 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
2872 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
2873 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2874 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
2875
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2876 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
2877 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2878 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2879 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2880 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
2881 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
2882 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2883 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2884
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2885 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
2886 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2887 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
2888 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
2889 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2890 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2891
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2892 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
2893 assert_equal('Base class: 42', o.ToString())
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2894 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2895 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2896
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2897 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
2898 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2899 class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2900 this.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
2901 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
2902 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
2903 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2904 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2905 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
2906 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
2907 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
2908 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2909 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2910 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
2911 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2912 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
2913
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2914 # base class with more than one object member
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2915 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
2916 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2917
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2918 class Result
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2919 this.success: bool
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2920 this.value: any = null
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2921 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2922
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2923 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
2924 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
2925 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
2926 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2927 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2928
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2929 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
2930 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
2931 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2932 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
2933
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
2934 # 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
2935 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
2936 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
2937 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
2938 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
2939 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
2940 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
2941 END
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 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
2943 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2944
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2945 def Test_using_base_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2946 var lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2947 vim9script
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2948
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2949 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
2950 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
2951 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
2952 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2953 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
2954 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2955 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2956
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2957 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
2958 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
2959 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
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
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2962 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
2963 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
2964 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2965 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2966
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2967 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
2968 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
2969 try
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2970 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
2971 finally
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2972 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
2973 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
2974 endtry
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2975 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2976
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2977 g:result = ''
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2978 With(ChildEE.new())
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2979 assert_equal('42/finally/exit', g:result)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2980 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
2981 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2982 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2983
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2984 # 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
2985 lines =<< trim END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2986 vim9script
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 class 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
2989 this.success: bool = false
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
2990 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
2991 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
2992 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2993 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2994
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2995 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
2996 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
2997 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
2998 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
2999 endclass
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3000
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3001 var obj = Child.new()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3002 assert_equal(true, obj.success)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3003 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3004 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3005 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3006
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3007 def Test_class_import()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3008 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
3009 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3010 export class Animal
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3011 this.kind: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3012 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3013 endclass
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3014 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3015 writefile(lines, 'Xanimal.vim', 'D')
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3016
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3017 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
3018 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3019 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
3020
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3021 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
3022 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
3023 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
3024 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
3025
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3026 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
3027 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
3028 assert_equal('Garfield', b.name)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3029 END
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3030 v9.CheckScriptSuccess(lines)
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3031 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3032
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3033 def Test_abstract_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3034 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
3035 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3036 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3037 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3038 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3039 class Person 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
3040 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3041 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3042 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
3043 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
3044 assert_equal(42, p.age)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3045 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3046 v9.CheckSourceSuccess(lines)
32670
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 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
3049 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3050 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3051 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3052 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3053 class Person 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
3054 this.age: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3055 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3056 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
3057 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3058 v9.CheckSourceFailure(lines, 'E1325: Method not found on class "Base": new', 8)
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3059
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3060 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
3061 abstract class Base
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3062 this.name: string
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3063 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3064 END
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3065 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
3066
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3067 # 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
3068 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
3069 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
3070 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
3071 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
3072 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
3073 endclass
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3074 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3075 v9.CheckSourceFailure(lines, 'E1359: Cannot define a "new" method in an abstract class', 4)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3076 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3077
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3078 def Test_closure_in_class()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3079 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
3080 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3081
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3082 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
3083 this.y: list<string> = ['B']
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3084
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3085 def new()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3086 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
3087 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3088 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3089
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3090 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
3091 assert_equal(['A'], g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3092 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3093 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3094 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3095
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3096 def Test_call_constructor_from_legacy()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3097 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
3098 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3099
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3100 var newCalled = 'false'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3101
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3102 class A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3103 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
3104 newCalled = 'true'
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3105 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3106 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3107
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3108 export def F(options = {}): any
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3109 return A
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3110 enddef
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 g:p = F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3113 legacy call p.new()
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('true', newCalled)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3115 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3116 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3117 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3118
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3119 def Test_defer_with_object()
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3120 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
3121 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3122
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3123 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
3124 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
3125 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
3126 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3127 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
3128 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
3129 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3130 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3131
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3132 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
3133 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
3134 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
3135 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3136 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3137
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3138 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
3139 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
3140 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
3141 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
3142 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3143 assert_equal('entered/called/exited', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3144 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3145 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3146 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3147
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3148 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
3149 vim9script
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3150
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3151 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
3152 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
3153 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
3154 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3155 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
3156 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
3157 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3158 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3159
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3160 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
3161 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
3162 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
3163 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3164 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
3165 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
3166 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3167 endclass
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3168
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3169 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
3170 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
3171 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
3172 F()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3173 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3174
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3175 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
3176 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
3177 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
3178 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
3179 })
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3180 assert_equal('entered-child/called/exited-child', g:result)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3181 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3182 v9.CheckSourceSuccess(lines)
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3183 unlet g:result
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3184 enddef
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3185
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3186 " 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
3187 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
3188 var lines =<< trim END
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3189 vim9script
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3190
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3191 class Observer
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3192 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3193
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3194 class Property
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3195 this.value: any
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3196
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3197 def Set(v: any)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3198 if v != this.value
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3199 this.value = v
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3200 endif
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3201 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3202
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3203 def Register(observer: Observer)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3204 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3205 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3206
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3207 class Bool extends Property
33070
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
3208 this.value2: bool
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3209 endclass
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3210
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3211 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
3212 obj.Register(who)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3213 enddef
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3214
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3215 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
3216 var myObserver = Observer.new()
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3217
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3218 Observe(p, myObserver)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3219
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3220 p.Set(true)
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3221 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3222 v9.CheckSourceSuccess(lines)
32764
d35204b890af patch 9.0.1701: vim9 crash when class member overridden
Christian Brabandt <cb@256bit.org>
parents: 32670
diff changeset
3223 enddef
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
3224
32772
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3225 " 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
3226 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
3227 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
3228 vim9script
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3229
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3230 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
3231 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
3232
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3233 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
3234 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
3235 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
3236 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3237
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3238 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
3239 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
3240 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3241 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3242
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3243 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
3244 endclass
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3245
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3246 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
3247 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
3248 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3249
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3250 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
3251 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
3252
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3253 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
3254 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
3255 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
3256 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3257 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
3258 enddef
0dc750a24875 patch 9.0.1703: Vim9 Calling a method in an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32764
diff changeset
3259
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3260 def Test_instanceof()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3261 var lines =<< trim END
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3262 vim9script
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3263
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3264 class Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3265 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3266
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3267 class Base2 extends Base1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3268 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3269
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3270 interface Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3271 endinterface
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3272
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3273 class Mix1 implements Intf1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3274 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3275
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3276 class Base3 extends Mix1
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3277 endclass
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3278
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3279 var b1 = Base1.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3280 var b2 = Base2.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3281 var b3 = Base3.new()
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3282
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3283 assert_true(instanceof(b1, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3284 assert_true(instanceof(b2, Base1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3285 assert_false(instanceof(b1, Base2))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3286 assert_true(instanceof(b3, Mix1))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3287 assert_false(instanceof(b3, []))
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3288 assert_true(instanceof(b3, [Base1, Base2, Intf1]))
33019
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3289
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3290 def Foo()
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3291 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
3292 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
3293 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
3294
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3295 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
3296 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
3297 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
3298 assert_true(instanceof(a3, Mix1))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3299 assert_false(instanceof(a3, []))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3300 assert_true(instanceof(a3, [Base1, Base2, Intf1]))
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3301 enddef
04c75e67ca30 patch 9.0.1801: Vim9 instanceof() fails in a def func
Christian Brabandt <cb@256bit.org>
parents: 33008
diff changeset
3302 Foo()
33291
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3303
4cb421ba3385 patch 9.0.1911: Vim9: segfault with null object and instanceof()
Christian Brabandt <cb@256bit.org>
parents: 33286
diff changeset
3304 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
3305 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
3306
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3307 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3308 v9.CheckSourceSuccess(lines)
32972
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3309 enddef
e4851934751a patch 9.0.1786: Vim9: need instanceof() function
Christian Brabandt <cb@256bit.org>
parents: 32960
diff changeset
3310
32812
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3311 " 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
3312 " 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
3313 " 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
3314 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
3315 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
3316 vim9script
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3317
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3318 class Widget
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3319 this._lnum: number = 1
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3320
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3321 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
3322 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
3323 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3324
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3325 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
3326 return ''
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3327 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3328 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3329
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3330 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
3331 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
3332 return '<Foo>'
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3333 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3334 endclass
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3335
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3336 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
3337 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
3338 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
3339 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
3340 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3341
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3342 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
3343 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
3344 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
3345 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3346 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
3347 enddef
57282f1d9e0f patch 9.0.1720: Vim9 class using wrong index for overridden method
Christian Brabandt <cb@256bit.org>
parents: 32772
diff changeset
3348
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
3349 " 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
3350 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
3351 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
3352 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
3353
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3354 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
3355 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
3356 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
3357 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
3358 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
3359 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
3360
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3361 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
3362 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
3363 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
3364 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
3365
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3366 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
3367 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
3368 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
3369
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3370 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
3371 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
3372 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
3373 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
3374
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3375 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
3376 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
3377 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
3378 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
3379
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3380 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
3381 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
3382 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
3383 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
3384
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3385 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
3386 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
3387 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
3388 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
3389 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
3390
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3391 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
3392 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
3393 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
3394 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
3395 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
3396
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3397 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
3398 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
3399 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
3400 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
3401 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
3402
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3403 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
3404 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
3405 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
3406 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
3407 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
3408
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3409 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
3410 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
3411 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
3412 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
3413 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
3414 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
3415 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
3416 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
3417 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
3418 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
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)
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
3421 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
3422
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3423 " 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
3424 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
3425 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
3426 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
3427
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3428 class A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3429 public this.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
3430 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
3431
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3432 class B extends A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3433 public this.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
3434 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
3435
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3436 class C extends B
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
3437 public this.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
3438 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
3439
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3440 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
3441 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
3442 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
3443
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3444 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
3445 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
3446 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
3447 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
3448
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3449 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
3450 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
3451 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
3452 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
3453 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
3454
5fd9fe58c791 patch 9.0.1737: Calling a base class method through an extended class fails
Christian Brabandt <cb@256bit.org>
parents: 32822
diff changeset
3455 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
3456 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
3457 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
3458 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
3459 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
3460 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
3461 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
3462 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3463 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
3464 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
3465
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3466 " 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
3467 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
3468 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
3469 vim9script
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3470
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3471 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
3472 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
3473 F0()
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3474 enddef
32898
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3475 endclass
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3476
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3477 def F0()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3478 assert_match('<SNR>\d\+_F\[1\]\.\.C\.M1\[1\]\.\.<SNR>\d\+_F0\[1\]$', expand('<stack>'))
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3479 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3480
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3481 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
3482 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
3483 enddef
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3484
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3485 F()
cbb5a593c92a patch 9.0.1758: vim9 no class identifiers in stack dumps
Christian Brabandt <cb@256bit.org>
parents: 32863
diff changeset
3486 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3487 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
3488 enddef
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3489
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3490 " 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
3491 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
3492 # 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
3493 var lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3494 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3495
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3496 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3497 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3498
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3499 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3500 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3501 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3502 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3503 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3504 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3505
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3506 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
3507 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
3508
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3509 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3510 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3511 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
3512
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3513 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3514 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3515 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3516 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
3517 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3518 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3519 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3520 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3521
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3522 # 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
3523 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3524 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3525
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3526 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3527 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3528
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3529 def new(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3530 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3531 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3532 return
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3533 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3534 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3535 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3536
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3537 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
3538 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
3539
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3540 var v1: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3541 v1 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3542 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
3543
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3544 def F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3545 var v2: C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3546 v2 = C.new(12345)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3547 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
3548 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3549 F()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3550 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3551 v9.CheckSourceSuccess(lines)
32903
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3552
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3553 # 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
3554 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3555 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3556
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3557 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3558 this._bufnr: number
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3559
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3560 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
3561 if !bufexists(this._bufnr)
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3562 this._bufnr = -1
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3563 return this
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3564 endif
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3565 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3566 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3567 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3568 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
3569
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3570 # 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
3571 lines =<< trim END
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3572 vim9script
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3573
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3574 class C
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3575 this._state: dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3576
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3577 def new(): dict<any>
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3578 this._state = {}
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3579 return this._state
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3580 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3581 endclass
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3582
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3583 var c = C.new()
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3584 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
3585 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3586 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
3587 enddef
54c01bb98b8e patch 9.0.1760: vim9 class problem with new() constructor
Christian Brabandt <cb@256bit.org>
parents: 32898
diff changeset
3588
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3589 " 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
3590 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
3591 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
3592 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3593
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3594 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
3595
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3596 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
3597 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
3598 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
3599 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
3600 else
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3601 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
3602 endif
32960
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3603 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3604
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3605 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
3606 this._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
3607 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3608
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3609 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
3610 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
3611 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
3612 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
3613 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3614
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3615 " 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
3616 " object.
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3617 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
3618 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
3619 vim9script
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3620
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3621 class C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3622 this.val: number
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3623 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
3624 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3625 endclass
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3626
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3627 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
3628 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
3629
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3630 var current: C
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3631 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
3632 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
3633 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
3634 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
3635
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3636 def F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3637 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
3638 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3639
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3640 def G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3641 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
3642 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3643
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3644 F()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3645 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
3646 G()
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3647 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
3648 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
3649 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
3650 enddef
d5c05e15cf81 patch 9.0.1780: Vim9 type not defined during object creation
Christian Brabandt <cb@256bit.org>
parents: 32903
diff changeset
3651
33393
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3652 " 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
3653 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
3654 # 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
3655 # 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
3656 # 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
3657 # Also different depths
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3658
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3659 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3660 # 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
3661 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3662
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3663 # 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
3664 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3665 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3666
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3667 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3668 this.val1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3669 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3670 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3671 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3672 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3673 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
3674 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3675 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
3676 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
3677
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3678 # 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
3679 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3680 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3681
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3682 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3683 this.val2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3684 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3685 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
3686 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3687 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3688 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
3689
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3690 # 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
3691 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3692 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3693
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3694 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3695 this.val3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3696 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3697 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
3698 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3699 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3700 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3701 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3702 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3703 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
3704
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3705 # 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
3706 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3707 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3708
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3709 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3710 this.val4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3711 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3712 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3713 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3714 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3715 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3716 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3717 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
3718
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3719 # 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
3720 # 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
3721
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3722 # 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
3723 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3724 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3725
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3726 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3727 this.val5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3728 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
3729 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3730 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3731 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3732 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
3733 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
3734 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
3735 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
3736
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3737 # 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
3738 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3739 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3740
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3741 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3742 this.val6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3743 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
3744 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3745 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3746 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3747 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
3748 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3749 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
3750 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
3751
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3752 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3753 # 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
3754 #
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3755
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3756 # lockvar from object method
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3757 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3758 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3759
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3760 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3761 public this.val1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3762 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3763 lockvar this.val1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3764 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3765 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3766 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
3767 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3768 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3769 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
3770
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3771 # lockvar from scriptlevel
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3772 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3773 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3774
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3775 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3776 public this.val2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3777 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3778 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
3779 lockvar o.val2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3780 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3781 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
3782
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3783 # 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
3784 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3785 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3786
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3787 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3788 public this.val3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3789 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3790 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
3791 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3792 lockvar o.val3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3793 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3794 Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3795 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3796 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
3797
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3798 # 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
3799 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3800 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3801
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3802 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3803 public this.val4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3804 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3805 def Lock(o: C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3806 lockvar o.val4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3807 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3808 Lock(C.new(3))
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3809 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3810 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
3811
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3812 # 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
3813 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3814 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3815
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3816 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3817 public this.val5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3818 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
3819 lockvar o_any.val5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3820 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3821 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3822 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
3823 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
3824 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3825 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
3826
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3827 # 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
3828 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3829 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3830
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3831 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3832 public this.val6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3833 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
3834 lockvar o_any.val6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3835 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3836 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3837 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
3838 C.Lock(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3839 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3840 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
3841 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3842
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3843 " 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
3844 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
3845
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3846 # 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
3847 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3848 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3849
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3850 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3851 public static sval1: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3852 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3853 lockvar sval1
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3854 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3855 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3856 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3857 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3858 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3859 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
3860
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3861 # 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
3862 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3863 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3864
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3865 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3866 public static sval2: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3867 def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3868 lockvar C.sval2
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3869 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3870 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3871 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3872 o.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3873 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3874 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
3875
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3876 # 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
3877 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3878 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3879
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3880 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3881 public static sval3: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3882 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3883 lockvar sval3
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3884 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3885 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3886 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3887 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3888 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
3889
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3890 # 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
3891 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3892 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3893
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3894 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3895 public static sval4: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3896 static def Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3897 lockvar C.sval4
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3898 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3899 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3900 C.Lock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3901 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3902 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
3903
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3904 # 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
3905 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3906 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3907
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3908 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3909 public static sval5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3910 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3911 lockvar C.sval5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3912 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3913 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
3914
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3915 # 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
3916 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3917 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3918
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3919 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3920 public static sval6: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3921 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3922 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3923 lockvar o.sval6
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3924 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3925 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
3926 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3927
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3928 " 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
3929 def Test_lockvar_argument()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3930 # Lockvar a function arg
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3931 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3932 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3933
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3934 def Lock(val: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3935 lockvar val
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3936 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3937
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3938 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
3939 Lock(d)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3940
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3941 d->extend({c: 3})
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3942 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3943 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
3944
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3945 # 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
3946 # 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
3947 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3948 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3949
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3950 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3951 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3952 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3953
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3954 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3955 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3956 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3957
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3958 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3959 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3960 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3961 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3962
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3963 # Lock a class.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3964 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3965 vim9script
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 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3968 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3969 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3970
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3971 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3972 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3973 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3974
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3975 Lock2(C)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3976 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3977 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3978
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3979 # Lock an object.
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3980 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3981 vim9script
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 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3984 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3985 endclass
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 def Lock2(sval: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3988 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3989 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3990
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
3991 Lock2(C.new())
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.CheckSourceSuccess(lines)
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 # 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
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
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4000 public static sval: list<number>
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4001 def Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4002 lockvar sval
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4003 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4004 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4005
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4006
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4007 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4008 o.Lock2()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4009 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4010 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
4011 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4012
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4013 " 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
4014 def Test_lockvar_this()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4015 # lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4016 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4017 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4018 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4019 def TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4020 lockvar this
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4021 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4022 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4023 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4024 o.TLock()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4025 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4026 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4027
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4028 # 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
4029 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4030 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4031 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4032 def TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4033 var four: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4034 lockvar four
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()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4038 o.TLock4()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4039 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4040 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
4041
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4042 # 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
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 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4046 def TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4047 var this5: number
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4048 lockvar this5
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4049 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4050 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4051 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4052 o.TLock5()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4053 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4054 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
4055 enddef
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 " 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
4058 def Test_lockvar_general()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4059 # 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
4060 var lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4061 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4062 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4063 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4064 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4065 lockvar o
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4066 lockvar C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4067 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4068 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4069
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4070 # 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
4071 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4072 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4073
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4074 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4075 public this.val: list<list<number>> = [ [1], [2], [3] ]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4076 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4077 def Lock2(obj: any)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4078 lockvar obj.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4079 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4080
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4081 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4082 Lock2(o)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4083 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4084 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
4085 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4086 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4087 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
4088 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4089 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4090 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4091 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4092 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
4093 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4094 v9.CheckSourceSuccess(lines)
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4095
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4096 # 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
4097 lines =<< trim END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4098 vim9script
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4099
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4100 class C
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4101 public this.val: list<list<number>> = [ [1], [2], [3] ]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4102 endclass
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4103
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4104 var o = C.new()
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4105 lockvar o.val[1]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4106 o.val[0] = [9]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4107 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
4108 try
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4109 o.val[1] = [999]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4110 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
4111 catch
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4112 assert_exception('E741:')
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4113 endtry
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4114 o.val[2] = [8]
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4115 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
4116 END
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4117 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
4118
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4119 # 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
4120 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4121 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4122
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4123 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4124 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4125 lockvar l
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4126 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4127 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4128
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4129 var l = [1]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4130 C.new().Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4131 l[0] = 11
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4132 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4133 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
4134
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4135 # lock a list element referenced by a private object variable
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4136 # 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
4137 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4138 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4139
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4140 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4141 this._v1: list<list<number>>
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4142 def Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4143 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
4144 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4145 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4146
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4147 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
4148 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
4149 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
4150
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4151 o.Lock()
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4152 l[0] = [22]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4153 l[1] = [33]
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4154 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4155 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
4156
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4157 # similar to the previous test, except the locking code is executing
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4158 # in a class that does not own the private variable.
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4159 # Note that the locking code is in a class has a private variable of
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4160 # the same name.
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4161 lines =<< trim END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4162 vim9script
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4163
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4164 class C2
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4165 this._v1: list<list<number>>
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4166 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
4167 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
4168 enddef
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4169 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4170
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4171 class C
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4172 this._v1: list<list<number>>
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4173 endclass
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4174
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4175 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
4176 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
4177 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
4178
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4179 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
4180 o2.Lock(o)
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4181 END
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
4182 v9.CheckSourceFailure(lines, 'E1333: Cannot access private 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
4183 enddef
016d8f863230 patch 9.0.1955: Vim9: lockvar issues with objects/classes
Christian Brabandt <cb@256bit.org>
parents: 33385
diff changeset
4184
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4185 " Test builtin islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4186 def Test_lockvar_islocked()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4187 # Can't lock class/object variable
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4188 # Lock class/object variable's value
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4189 # Lock item of variabl's value (a list item)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4190 # varible is at index 1 within class/object
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4191 var lines =<< trim END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4192 vim9script
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4193
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4194 class C
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4195 this.o0: list<list<number>> = [ [0], [1], [2]]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4196 this.o1: list<list<number>> = [[10], [11], [12]]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4197 static c0: list<list<number>> = [[20], [21], [22]]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4198 static c1: list<list<number>> = [[30], [31], [32]]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4199 endclass
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4200
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4201 def LockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4202 lockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4203 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4204
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4205 def UnlockIt(arg: any)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4206 unlockvar arg
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4207 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4208
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4209 var obj = C.new()
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4210 #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
4211
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4212 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4213 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
4214 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
4215 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4216 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4217 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4218
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4219 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
4220 assert_equal(1, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4221 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
4222 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
4223 UnlockIt(obj.o1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4224 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4225 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
4226
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4227 lockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4228 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4229 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
4230 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
4231 unlockvar obj.o1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4232 assert_equal(0, islocked("obj.o1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4233 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
4234
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4235 # Same thing, but with a static
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4236
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4237 try
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4238 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
4239 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
4240 catch
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4241 call assert_exception('E1335:')
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4242 endtry
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4243
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4244 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
4245 assert_equal(1, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4246 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
4247 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
4248 UnlockIt(C.c1)
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4249 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4250 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
4251
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4252 lockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4253 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4254 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
4255 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
4256 unlockvar C.c1[0]
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4257 assert_equal(0, islocked("C.c1"))
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4258 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
4259 END
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4260 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
4261
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4262 # 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
4263 # 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
4264 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
4265 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4266
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4267 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
4268 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
4269 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
4270 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
4271
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4272 class C0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4273 this.o0: list<list<number>> = l0o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4274 this.o1: list<list<number>> = l0o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4275 static c0: list<list<number>> = l0c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4276 static c1: list<list<number>> = l0c1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4277 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
4278 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
4279 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4280 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
4281 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
4282 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4283 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4284
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4285 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
4286 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
4287 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
4288 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
4289
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4290 class C2
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4291 this.o0: list<list<number>> = l2o0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4292 this.o1: list<list<number>> = l2o1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4293 static c0: list<list<number>> = l2c0
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4294 static c1: list<list<number>> = l2c1
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4295 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
4296 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
4297 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4298 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
4299 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
4300 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4301 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4302
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4303 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
4304 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
4305
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4306 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
4307
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4308 # 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
4309 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
4310 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
4311 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
4312 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
4313 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
4314
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4315 #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
4316
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4317 # 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
4318 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
4319 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
4320 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
4321
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4322 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
4323 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
4324 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
4325 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
4326
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4327 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
4328
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4329 # 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
4330 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
4331 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
4332 # 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
4333 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
4334 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
4335
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4336 # 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
4337 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
4338 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
4339 # 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
4340 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
4341 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
4342
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4343
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4344 # 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
4345 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
4346 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
4347 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
4348
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4349 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4350 # 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
4351 #
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4352
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4353 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
4354
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4355 # 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
4356 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
4357 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
4358 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
4359 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
4360 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
4361
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4362 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
4363
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4364 # 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
4365 try
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4366 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
4367 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
4368 catch
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4369 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
4370 endtry
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4371
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4372 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
4373
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4374 # 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
4375 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
4376 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
4377 # 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
4378 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
4379 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
4380
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4381 # 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
4382 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
4383 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
4384 # 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
4385 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
4386 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
4387
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4388
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4389 # 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
4390 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
4391 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
4392 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
4393 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
4394 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4395 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
4396
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4397 # 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
4398 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
4399 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4400
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4401 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
4402 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
4403 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
4404 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4405 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
4406 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
4407 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4408 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4409 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
4410
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4411 # 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
4412 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
4413 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
4414
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4415 # 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
4416 ### 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
4417 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
4418
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4419 #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
4420 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
4421 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
4422 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
4423 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
4424 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
4425 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4426 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
4427 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4428
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4429 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
4430 # 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
4431 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
4432 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4433
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4434 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
4435 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
4436 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
4437 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4438 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
4439 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
4440 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4441 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4442 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
4443 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
4444 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
4445 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4446 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
4447
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4448 # 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
4449 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
4450 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4451
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4452 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
4453 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4454 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
4455
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4456 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
4457 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4458
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4459 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
4460 this.val = { key: "value" }
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4461 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
4462 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
4463 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4464 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4465 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
4466 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
4467 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4468 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
4469
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4470 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
4471 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4472
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4473 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
4474 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
4475 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
4476 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4477 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4478 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
4479 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
4480 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4481 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "C": notobjmember')
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4482
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4483 # 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
4484 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
4485 vim9script
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4486
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4487 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
4488 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
4489 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
4490 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
4491 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4492 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
4493 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
4494 enddef
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4495 endclass
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4496 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
4497 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
4498 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
4499 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
4500 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
4501 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
4502 END
f99f5a56ff27 patch 9.0.2015: Vim9: does not handle islocked() from a method correctly
Christian Brabandt <cb@256bit.org>
parents: 33517
diff changeset
4503 v9.CheckSourceSuccess(lines)
33503
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4504 enddef
f72004b37b2b patch 9.0.2001: Vim9: segfault with islocked()
Christian Brabandt <cb@256bit.org>
parents: 33501
diff changeset
4505
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4506 " Test for a private object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4507 def Test_private_object_method()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4508 # Try calling a private method using an object (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4509 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
4510 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4511
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4512 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4513 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4514 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4515 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4516 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4517 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
4518 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4519 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
4520 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 9)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4521
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4522 # Try calling a private method using an object (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4523 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4524 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4525
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4526 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4527 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4528 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4529 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4530 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4531 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4532 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
4533 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4534 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4535 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4536 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4537 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4538
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4539 # Use a private method from another object method (in script context)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4540 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4541 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4542
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4543 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4544 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4545 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4546 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4547 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4548 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4549 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4550 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4551 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
4552 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
4553 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4554 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
4555
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4556 # Use a private method from another object method (def function context)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4557 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4558 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4559
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4560 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4561 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4562 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4563 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4564 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4565 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4566 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4567 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4568 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4569 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
4570 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
4571 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4572 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4573 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4574 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
4575
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4576 # Try calling a private method without the "this" prefix
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4577 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4578 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4579
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4580 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4581 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4582 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4583 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4584 def Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4585 return _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4586 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4587 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4588 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
4589 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4590 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4591 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
4592
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4593 # Try calling a private method using the class name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4594 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4595 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4596
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4597 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4598 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4599 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4600 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4601 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4602 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4603 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4604 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 8)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4605
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4606 # Define two private methods with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4607 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4608 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4609
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4610 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4611 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4612 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4613 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4614 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4615 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4616 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
4617 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4618 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
4619
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4620 # Define a private method and a object method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4621 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4622 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4623
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4624 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4625 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4626 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4627 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4628 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4629 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4630 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
4631 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4632 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
4633
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4634 # Define an object method and a private method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4635 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4636 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4637
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4638 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4639 def Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4640 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4641 def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4642 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4643 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4644 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
4645 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4646 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
4647
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4648 # Call a public method and a private method from a private method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4649 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4650 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4651
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4652 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4653 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4654 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4655 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4656 def _Bar(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4657 return 200
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4658 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4659 def _Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4660 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
4661 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
4662 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4663 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4664 this._Baz()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4665 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4666 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4667 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
4668 a.T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4669 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4670 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
4671
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4672 # Try calling a private method from another class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4673 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4674 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4675
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4676 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4677 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4678 return 100
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4679 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4680 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4681 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4682 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4683 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
4684 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4685 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4686 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4687 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
4688 b.Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4689 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4690 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4691
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4692 # Call a private object method from a child class object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4693 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4694 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4695 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4696 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4697 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4698 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4699 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4700 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
4701 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4702 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4703 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4704 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
4705 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4706 return this._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4707 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4708 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4709 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
4710 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
4711 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4712 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
4713
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4714 # Call a private object method from a child class object
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4715 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4716 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4717 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4718 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4719 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4720 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4721 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4722 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
4723 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4724 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4725 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4726 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
4727 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4728 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4729 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4730 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
4731 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
4732 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
4733 v9.CheckSourceFailure(lines, 'E1366: Cannot access private 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
4734
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4735 # 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
4736 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4737 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4738 def _Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4739 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4740 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4741 var a = _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4742 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4743 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
4744 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4745
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4746 " Test for an private class method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4747 def Test_private_class_method()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4748 # Try calling a class private method (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4749 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
4750 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4751
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4752 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4753 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
4754 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4755 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4756 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4757 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4758 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
4759 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 8)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4760
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4761 # Try calling a class private method (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4762 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4763 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4764
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4765 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4766 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
4767 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4768 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4769 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4770 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4771 A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4772 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4773 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4774 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4775 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4776
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4777 # Try calling a class private method using an object (at the script level)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4778 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4779 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4780
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4781 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4782 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
4783 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4784 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4785 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4786 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
4787 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4788 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4789 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 9)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4790
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4791 # Try calling a class private method using an object (from a def function)
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4792 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4793 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4794
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4795 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4796 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
4797 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4798 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4799 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4800 def T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4801 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
4802 a._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4803 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4804 T()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4805 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4806 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 2)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4807
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4808 # Use a class private method from an object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4809 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4810 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4811
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4812 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4813 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
4814 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4815 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4816 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
4817 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
4818 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4819 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4820 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
4821 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4822 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4823 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
4824
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
4825 # Use a class private method from another class private method without the
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
4826 # 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
4827 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4828 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4829
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4830 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4831 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
4832 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4833 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4834 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
4835 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
4836 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4837 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
4838 _Foo2()
33025
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 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4841 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
4842 a.Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4843 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4844 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
4845
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4846 # Declare a class method and a class private method with the same name
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4847 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4848 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4849
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4850 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4851 static def _Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4852 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4853 static def 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 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4858 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
4859
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4860 # Try calling a class private method from another class
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4861 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4862 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4863
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4864 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4865 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
4866 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4867 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4868 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4869 class B
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4870 def Foo(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4871 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4872 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4873 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4874 var b = B.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, b.Foo())
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4876 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4877 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4878
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4879 # Call a private class method from a child class object method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4880 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4881 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4882 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4883 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
4884 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4885 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4886 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4887 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
4888 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4889 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4890 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4891 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
4892 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4893 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4894 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4895 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4896 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
4897 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
4898 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4899 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4900
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4901 # Call a private class method from a child class private class method
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4902 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4903 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4904 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4905 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
4906 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4907 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4908 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4909 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
4910 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4911 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4912 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4913 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
4914 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
4915 return A._Foo()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4916 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4917 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4918 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
4919 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4920 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo()', 1)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4921
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4922 # Call a private class method from a child class object
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4923 lines =<< trim END
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4924 vim9script
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4925 class A
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4926 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
4927 return 1234
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4928 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4929 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4930 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
4931 def Bar()
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4932 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4933 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4934 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
4935 def Baz(): number
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4936 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4937 endclass
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4938 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
4939 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
4940 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4941 v9.CheckSourceFailure(lines, 'E1325: Method not found on class "C": _Foo', 16)
33025
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4942 enddef
1d18c7fe609f patch 9.0.1804: Vim9: no support for private object methods
Christian Brabandt <cb@256bit.org>
parents: 33019
diff changeset
4943
33027
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4944 " 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
4945 " argument.
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4946 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
4947 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
4948 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4949
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4950 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
4951 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
4952 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
4953 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4954 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4955
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4956 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
4957 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
4958 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4959
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4960 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
4961 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
4962 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4963
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4964 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
4965 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
4966 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4967 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
4968
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4969 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
4970 vim9script
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4971
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4972 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
4973 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
4974 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
4975 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4976 endclass
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4977
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4978 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
4979 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
4980 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4981
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4982 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
4983 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
4984 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4985
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4986 Baz()
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4987 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
4988 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
4989 enddef
669898c9a6c3 patch 9.0.1805: Vim9: problem compiling object method as function call arg
Christian Brabandt <cb@256bit.org>
parents: 33025
diff changeset
4990
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4991 def Test_static_inheritence()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4992 # 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
4993 var lines =<< trim END
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4994 vim9script
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4995
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
4996 class 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
4997 static _svar: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4998 this._mvar: number
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
4999 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
5000 _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
5001 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
5002 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5003 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
5004 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
5005 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5006 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
5007 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
5008 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5009 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5010
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5011 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
5012 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
5013 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
5014 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5015 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5016
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5017 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
5018 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
5019 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
5020 enddef
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5021
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5022 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
5023 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
5024 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
5025 enddef
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5026 endclass
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5027
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5028 var oa = A.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5029 var ob = B.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5030 var oc = C.new()
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5031 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
5032 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
5033 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
5034
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
5035 assert_fails('echo oc.AccessPrivateStaticThroughClassName()', 'E1333: Cannot access private 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
5036
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5037 # 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
5038 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
5039 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
5040 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
5041 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5042 v9.CheckSourceSuccess(lines)
33204
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5043 enddef
36aebbf8389f patch 9.0.1880: Vim9: Need more tests for inheritance
Christian Brabandt <cb@256bit.org>
parents: 33201
diff changeset
5044
33047
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5045 " 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
5046 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
5047 # 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
5048 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
5049 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5050 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5051 this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5052 this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5053 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5054 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5055 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
5056
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5057 # Duplicate private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5058 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
5059 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5060 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5061 this._val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5062 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5063 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5064 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5065 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
5066
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5067 # 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
5068 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
5069 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5070 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5071 public this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5072 public this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5073 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5074 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5075 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
5076
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5077 # Duplicate private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5078 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
5079 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5080 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5081 this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5082 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5083 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5084 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5085 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
5086
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5087 # Duplicate public and private member variable
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5088 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
5089 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5090 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5091 this._val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5092 public this.val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5093 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5094 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5095 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
5096
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5097 # 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
5098 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
5099 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5100 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5101 static s: string = "abc"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5102 static _s: string = "def"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5103 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5104 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5105 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
5106
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5107 # Duplicate public and private 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
5108 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
5109 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5110 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5111 public static s: string = "abc"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5112 static _s: string = "def"
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5113 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5114 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5115 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
5116
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5117 # 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
5118 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
5119 vim9script
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5120 class C
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5121 static val = 10
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5122 this.val = 20
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5123 def new()
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5124 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5125 endclass
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5126 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
5127 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
5128 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
5129 END
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
5130 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
5131
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5132 # 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
5133 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
5134 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5135 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5136 this.val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5137 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5138 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
5139 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5140 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5141 this.val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5142 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5143 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5144 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
5145
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5146 # Duplicate object private 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
5147 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
5148 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5149 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5150 this._val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5151 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5152 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
5153 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5154 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5155 this._val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5156 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5157 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5158 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
5159
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5160 # Duplicate object private 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
5161 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
5162 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5163 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5164 this.val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5165 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5166 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
5167 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5168 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5169 this._val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5170 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5171 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5172 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
5173
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5174 # 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
5175 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
5176 vim9script
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5177 class A
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5178 this._val = 10
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5179 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5180 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
5181 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5182 class C extends B
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5183 this.val = 20
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5184 endclass
8362975375a4 patch 9.0.1822: Vim9: no check for duplicate members in extended classes
Christian Brabandt <cb@256bit.org>
parents: 33068
diff changeset
5185 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5186 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
5187
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5188 # 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
5189 lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5190 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5191 class A
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5192 public static svar2: number
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5193 public static svar: number
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5194 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5195 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5196 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
5197 enddef
9ef43d02dd8f patch 9.0.1814: Vim9 no error on duplicate object member var
Christian Brabandt <cb@256bit.org>
parents: 33027
diff changeset
5198
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5199 " Test for accessing a private member outside a class in a def function
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5200 def Test_private_member_access_outside_class()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5201 # private object member variable
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5202 var lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5203 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5204 class A
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5205 this._val = 10
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5206 def GetVal(): number
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5207 return this._val
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5208 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5209 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5210 def T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5211 var a = A.new()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5212 a._val = 20
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5213 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5214 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5215 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
5216 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_val" in class "A"', 2)
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5217
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5218 # access a non-existing private object member variable
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5219 lines =<< trim END
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5220 vim9script
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5221 class A
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5222 this._val = 10
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5223 endclass
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5224 def T()
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5225 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
5226 a._a = 1
33075
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5227 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5228 T()
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5229 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5230 v9.CheckSourceFailure(lines, 'E1326: Variable not found on object "A": _a', 2)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5231
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5232 # private static member variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5233 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5234 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5235 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5236 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5237 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5238 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5239 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5240 var x = a._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5241 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5242 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5243 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5244 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
5245
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5246 # private static member variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5247 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5248 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5249 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5250 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5251 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5252 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5253 var a = A.new()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5254 a._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5255 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5256 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5257 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5258 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
5259
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5260 # private static class variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5261 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5262 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5263 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5264 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5265 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5266 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5267 var x = A._val
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5268 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5269 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5270 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
5271 v9.CheckSourceFailure(lines, 'E1333: Cannot access private variable "_val" in class "A"', 1)
33173
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5272
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5273 # private static class variable
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5274 lines =<< trim END
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5275 vim9script
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5276 class A
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5277 static _val = 10
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5278 endclass
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5279 def T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5280 A._val = 3
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5281 enddef
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5282 T()
9efd99a717c1 patch 9.0.1867: Vim9: access to interface statics possible
Christian Brabandt <cb@256bit.org>
parents: 33167
diff changeset
5283 END
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
5284 v9.CheckSourceFailure(lines, 'E1333: Cannot access private 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
5285 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5286
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5287 " 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
5288 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
5289 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
5290 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5291 interface A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5292 this.val: number
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5293 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5294 class B implements A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
5295 public this.val = 10
33088
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5296 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5297 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5298 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
5299
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5300 lines =<< trim END
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5301 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5302 interface A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5303 this.val: number
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5304 endinterface
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5305 class B implements A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5306 public this.val = 10
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5307 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5308 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5309 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
5310 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5311
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5312 " 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
5313 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
5314 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
5315 vim9script
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5316 class A
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5317 this.val: number
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5318 endclass
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5319 def T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5320 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
5321 a.val = 20
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5322 enddef
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5323 T()
667a17904f64 patch 9.0.1829: Vim9 missing access-checks for private vars
Christian Brabandt <cb@256bit.org>
parents: 33075
diff changeset
5324 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5325 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
5326 enddef
0346ff4c3ee7 patch 9.0.1824: Vim9: private members may be modifiable
Christian Brabandt <cb@256bit.org>
parents: 33070
diff changeset
5327
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5328 " 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
5329 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
5330 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
5331 vim9script
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5332 class A
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5333 this.var1: number = 10
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5334 public static var2: list<number> = [1, 2]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5335 public static var3: dict<number> = {a: 1, b: 2}
33109
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5336 static _priv_var4: number = 40
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5337 endclass
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5338 def T()
33160
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5339 assert_equal([1, 2], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5340 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
5341 A.var2 = [3, 4]
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5342 A.var3 = {c: 3, d: 4}
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5343 assert_equal([3, 4], A.var2)
4ecf54d709b3 patch 9.0.1862: Vim9 Garbage Collection issues
Christian Brabandt <cb@256bit.org>
parents: 33109
diff changeset
5344 assert_equal({c: 3, d: 4}, A.var3)
33456
4a62e78803db patch 9.0.1982: vim9: clean up from v9.0.1955
Christian Brabandt <cb@256bit.org>
parents: 33446
diff changeset
5345 assert_fails('echo A._priv_var4', 'E1333: Cannot access private 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
5346 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5347 T()
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5348 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5349 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
5350 enddef
2b5cc29b0a0e patch 9.0.1838: Vim9: Cannot modify class member vars from def function
Christian Brabandt <cb@256bit.org>
parents: 33092
diff changeset
5351
33201
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5352 " 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
5353 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
5354 var lines =<< trim END
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5355 vim9script
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5356 class A
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5357 public static svar1: list<number> = [1]
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5358 public static svar2: list<number> = [2]
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5359 endclass
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5360
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5361 A.svar1->add(3)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5362 A.svar2->add(4)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5363 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
5364 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
5365
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5366 def Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5367 A.svar1->add(7)
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5368 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
5369 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
5370 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
5371 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5372 Foo()
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5373 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5374 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
5375
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5376 # 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
5377 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5378 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5379 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5380 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5381 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5382 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5383
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5384 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
5385 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5386 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
5387 v9.CheckSourceFailure(lines, 'E1337: Class variable "svar2" not found in 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
5388
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5389 # 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
5390 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5391 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5392 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5393 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5394 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5395 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5396
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5397 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
5398 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
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, '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
5401
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5402 # 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
5403 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5404 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5405 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5406 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5407 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5408 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5409
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5410 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5411 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
5412 echo a.svar2
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5413 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5414 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5415 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5416 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
5417
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5418 # 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
5419 lines =<< trim END
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5420 vim9script
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5421 class A
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5422 public this.var1: number
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5423 public static svar2: list<number> = [1]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5424 endclass
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5425
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5426 def T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5427 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
5428 a.svar2 = [2]
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5429 enddef
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5430 T()
52b121d4feb5 patch 9.0.1887: Vim9: class members are accessible via object
Christian Brabandt <cb@256bit.org>
parents: 33223
diff changeset
5431 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5432 v9.CheckSourceFailure(lines, '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
5433 enddef
36c13b964eb3 patch 9.0.1879: Vim9: incorrect duplicate class member detection
Christian Brabandt <cb@256bit.org>
parents: 33173
diff changeset
5434
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
5435 " 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
5436 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
5437 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
5438 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
5439
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5440 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
5441 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
5442 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
5443
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5444 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
5445 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
5446 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
5447 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
5448 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
5449
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5450 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
5451 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
5452 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
5453 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
5454 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
5455
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5456 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
5457 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
5458 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
5459
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5460 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
5461 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
5462 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
5463
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5464 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
5465 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
5466 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
5467 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5468 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
5469 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
5470
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5471 " 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
5472 " 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
5473 " 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
5474 " 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
5475 " 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
5476 " 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
5477 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5478 " 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
5479 " 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
5480 " 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
5481 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5482 " 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
5483 " 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
5484 " 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
5485 " 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
5486 " 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
5487 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5488 " 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
5489 " 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
5490 " 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
5491 " 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
5492 " 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
5493 " 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
5494 " 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
5495 " 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
5496 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5497 " 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
5498 " 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
5499 " 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
5500 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5501 " 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
5502 " 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
5503 " 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
5504 "
71a097aab64d patch 9.0.1883: Vim9: Calling an interface method using a child object fails
Christian Brabandt <cb@256bit.org>
parents: 33204
diff changeset
5505 " 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
5506 " 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
5507 " 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
5508 " END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5509 " 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
5510 " 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
5511
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5512 " Test for abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5513 def Test_abstract_method()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5514 # Use two abstract methods
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5515 var lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5516 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5517 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5518 def M1(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5519 return 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5520 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5521 abstract def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5522 abstract def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5523 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5524 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5525 def M2(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5526 return 20
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5527 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5528 def M3(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5529 return 30
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5530 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5531 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5532 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5533 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
5534 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5535 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5536
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5537 # 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
5538 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5539 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5540 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5541 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5542 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5543 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5544 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5545 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5546 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
5547
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5548 # 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
5549 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5550 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5551 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5552 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5553 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5554 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5555 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5556 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5557 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
5558
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5559 # 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
5560 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5561 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5562 interface A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5563 abstract def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5564 endinterface
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5565 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
5566 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
5567 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5568 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5569 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
5570 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5571
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5572 # Abbreviate the "abstract" keyword
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5573 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5574 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5575 class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5576 abs def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5577 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5578 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5579 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
5580
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5581 # 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
5582 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5583 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5584 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5585 abstract this.val = 10
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5586 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5587 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5588 v9.CheckSourceFailure(lines, 'E1371: Abstract must be followed by "def" or "static"', 3)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5589
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5590 # Use a static abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5591 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5592 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5593 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5594 abstract static def Foo(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5595 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5596 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5597 static def Foo(): number
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5598 return 4
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5599 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5600 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5601 assert_equal(4, B.Foo())
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5602 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5603 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5604
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5605 # 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
5606 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5607 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5608 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5609 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
5610 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5611 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5612 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
5613 return []
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5614 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5615 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5616 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5617 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
5618
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5619 # Use an abstract class to invoke an abstract method
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5620 # FIXME: This should fail
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5621 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5622 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5623 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5624 abstract static def Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5625 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5626 A.Foo()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5627 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5628 v9.CheckSourceSuccess(lines)
33217
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5629
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5630 # 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
5631 lines =<< trim END
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5632 vim9script
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5633 abstract class A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5634 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
5635 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5636 class B extends A
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5637 def Foo(): list<number>
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5638 return [3, 5]
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5639 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5640 endclass
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5641 def Bar(c: B)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5642 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
5643 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5644 var b = B.new()
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5645 Bar(b)
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5646 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5647 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5648 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5649
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5650 " 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
5651 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
5652 # 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
5653 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5654 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5655
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5656 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5657 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5658 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5659 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5660 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5661
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5662 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5663 def Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5664 Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5665 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5666 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5667
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5668 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5669 b.Bar()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5670 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5671 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
5672 enddef
499ba27ba0f6 patch 9.0.1885: Vim9: no support for abstract methods
Christian Brabandt <cb@256bit.org>
parents: 33211
diff changeset
5673
33227
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5674 " 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
5675 " script context.
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5676 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
5677 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5678 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
5679 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5680 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5681 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
5682 return ['a', 'b']
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5683 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5684 def Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5685 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
5686 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
5687 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5688 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5689
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5690 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5691 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
5692 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
5693 t_a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5694 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5695
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5696 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
5697 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
5698 a.Bar()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5699 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5700 END
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5701 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
5702
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5703 # script context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5704 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5705 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5706 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5707 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
5708 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5709 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5710 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5711
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5712 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
5713 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
5714 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5715 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
5716
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5717 # def function context
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5718 lines =<< trim END
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5719 vim9script
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5720 class A
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5721 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
5722 return 'foo'
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5723 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5724 endclass
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5725
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5726 def T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5727 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
5728 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
5729 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5730 T()
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
5731 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5732 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
5733 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5734
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5735 def Test_class_variable()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5736 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5737 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5738
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5739 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5740 public static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5741 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5742 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5743 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5744 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5745 assert_equal(10, val)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5746 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5747 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5748
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5749 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5750 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5751
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5752 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
5753 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5754 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5755 a.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5756 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5757 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5758
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5759 def T1(a1: A)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5760 a1.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5761 A.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5762 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5763 T1(b)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5764
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5765 A.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5766 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
5767 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5768 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5769
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5770 # 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
5771 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5772 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5773
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5774 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5775 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5776 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5777
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5778 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5779 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5780 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5781 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5782 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5783 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5784 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5785 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
5786
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5787 # 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
5788 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5789 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5790
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5791 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5792 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5793 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5794
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5795 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5796 static def ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5797 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5798 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5799 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5800 B.ClassFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5801 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5802 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
5803
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5804 # 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
5805 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5806 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5807
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5808 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5809 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5810 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5811
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5812 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5813 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5814 val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5815 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5816 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5817 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5818 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5819 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5820 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
5821
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5822 # 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
5823 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5824 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5825
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5826 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5827 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5828 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5829
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5830 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5831 def ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5832 var i = val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5833 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5834 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5835 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5836 b.ObjFunc()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5837 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5838 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
5839
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5840 # 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
5841 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5842 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5843
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5844 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5845 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5846 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5847 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5848 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5849 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5850 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
5851
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5852 # 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
5853 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5854 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5855
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5856 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5857 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5858 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5859 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5860 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5861 END
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
5862 v9.CheckSourceFailure(lines, 'E1337: Class variable "val" not found in class "A"', 7)
33260
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5863
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5864 # 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
5865 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5866 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5867
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5868 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5869 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5870 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5871
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5872 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5873 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5874 a.val = 20
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5875 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5876 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5877 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5878 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
5879
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5880 # 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
5881 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5882 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5883
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5884 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5885 static val: number = 10
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5886 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5887 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5888 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5889 var i = a.val
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5890 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5891 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5892 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5893 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
5894 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5895
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5896 " 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
5897 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
5898 # 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
5899 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5900 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5901 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5902 static sval = 100
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5903 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5904 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5905 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5906 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5907 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5908 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5909 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5910
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5911 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5912 static sval = 200
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5913 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5914 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5915 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5916 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5917 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5918 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5919 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5920
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5921 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
5922 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5923 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5924
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5925 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
5926 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5927 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5928
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5929 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
5930 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
5931 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5932 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
5933 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5934 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
5935 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
5936 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
5937 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5938 v9.CheckSourceSuccess(lines)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5939
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5940 # 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
5941 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5942 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5943 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5944 static sval = 100
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5945 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5946 assert_equal(100, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5947 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5948 def GetVal(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5949 return sval
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5950 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5951 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5952
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5953 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5954 static sval = 200
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5955 static def Check()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5956 assert_equal(200, sval)
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5957 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5958 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5959
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5960 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
5961 return aa.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5962 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5963
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5964 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
5965 return bb.GetVal()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5966 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5967
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5968 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
5969 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
5970 var a = A.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5971 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
5972 var b = B.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5973 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
5974 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
5975 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
5976 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5977 v9.CheckSourceSuccess(lines)
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
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5980 " 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
5981 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
5982 # 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
5983 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5984 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5985 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5986 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5987 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5988 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5989 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5990 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5991 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
5992 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
5993
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5994 # 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
5995 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5996 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5997 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5998 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
5999 echo "foo"
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6000 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6001 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6002 def T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6003 A.Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6004 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6005 T()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6006 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6007 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
6008 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6009
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6010 " 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
6011 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
6012 # Duplicate instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6013 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6014 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6015 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6016 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6017 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6018 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6019 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6020 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6021 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6022 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
6023
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6024 # Duplicate private instance method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6025 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6026 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6027 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6028 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6029 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6030 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6031 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6032 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
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, '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
6035
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6036 # Duplicate class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6037 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6038 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6039 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6040 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6041 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6042 static def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6043 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6044 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6045 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6046 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
6047
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6048 # Duplicate private class method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6049 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6050 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6051 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6052 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6053 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6054 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6055 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6056 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6057 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6058 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
6059
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6060 # Duplicate private class and object method
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6061 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6062 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6063 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6064 def _Foo()
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 static def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6067 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6068 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6069 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6070 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
6071 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6072
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6073 " 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
6074 " methods.
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6075 def Test_instance_method_access_level()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6076 # Private method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6077 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6078 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6079 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6080 def Foo()
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 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6083 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6084 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6085 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6086 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6087 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6088 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6089 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6090 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
6091
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6092 # Public method in subclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6093 lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6094 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6095 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6096 def _Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6097 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6098 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6099 class B extends A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6100 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6101 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6102 def Foo()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6103 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6104 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6105 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6106 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
6107 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6108
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6109 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
6110 var lines =<< trim END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6111 vim9script
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6112 class A
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6113 endclass
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 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6116 class C extends B
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6117 public static rw_class_var = 1
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6118 public this.rw_obj_var = 2
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6119 static def ClassMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6120 return 3
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6121 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6122 def ObjMethod(): number
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6123 return 4
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6124 enddef
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6125 endclass
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6126 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
6127 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
6128 var c = C.new()
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6129 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
6130 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
6131 END
aba1fa2b7d1e patch 9.0.1898: Vim9: restrict access to static vars
Christian Brabandt <cb@256bit.org>
parents: 33227
diff changeset
6132 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
6133 enddef
3672d3d13524 patch 9.0.1888: Vim9: Problem trying to invoke class method
Christian Brabandt <cb@256bit.org>
parents: 33225
diff changeset
6134
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6135 " A interface cannot have a static variable or a static method or a private
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6136 " variable or a private 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
6137 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
6138 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
6139 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6140 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
6141 static num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6142 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6143 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6144 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
6145
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6146 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
6147 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6148 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
6149 static _num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6150 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6151 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6152 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
6153
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6154 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
6155 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6156 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
6157 public static num: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6158 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6159 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6160 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
6161
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6162 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
6163 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6164 interface A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6165 public static num: number
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6166 endinterface
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6167 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6168 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
6169
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6170 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
6171 vim9script
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6172 interface A
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6173 static _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
6174 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6175 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6176 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
6177
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6178 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
6179 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6180 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
6181 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
6182 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6183 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6184 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
6185
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6186 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
6187 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6188 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
6189 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
6190 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6191 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6192 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
6193
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6194 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
6195 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6196 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
6197 this._Foo: 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
6198 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6199 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6200 v9.CheckSourceFailure(lines, 'E1379: Private 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
6201
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6202 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
6203 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6204 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
6205 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
6206 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6207 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6208 v9.CheckSourceFailure(lines, 'E1380: Private 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
6209 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6210
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6211 " 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
6212 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
6213 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
6214 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6215 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
6216 this.var1: 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
6217 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
6218 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6219 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6220 this.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
6221 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
6222 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6223 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
6224 this.var1 = [1, 2]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6225 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
6226 enddef
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6227 this.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
6228 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
6229 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6230 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6231 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6232 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
6233
33506
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6234 # 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
6235 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
6236 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6237 interface A
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6238 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6239 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
6240 endinterface
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6241 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
6242 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6243 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6244 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
6245
33278
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6246 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
6247 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6248 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
6249 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
6250 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6251 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6252 this.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
6253 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6254 class C implements A, B
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6255 this.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
6256 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6257 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6258 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
6259
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6260 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
6261 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6262 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
6263 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
6264 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6265 interface B extends A
33372
3e9a91624b40 patch 9.0.1945: Vim9: missing support for ro-vars in interface
Christian Brabandt <cb@256bit.org>
parents: 33343
diff changeset
6266 this.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
6267 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6268 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
6269 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
6270 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6271 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6272 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6273 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
6274
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6275 # 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
6276 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
6277 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6278 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
6279 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6280 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
6281 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6282 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6283 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
6284
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6285 # 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
6286 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
6287 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6288 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
6289 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6290 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
6291 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6292 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6293 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
6294
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6295 # 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
6296 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
6297 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6298 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
6299 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6300 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
6301 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6302 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6303 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
6304
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6305 # 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
6306 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
6307 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6308 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
6309 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6310 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
6311 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6312 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
6313 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6314 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6315 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
6316
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6317 # 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
6318 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
6319 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6320 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
6321 this.val1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6322 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6323 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
6324 this.val2: string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6325 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6326 interface C extends B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6327 this.val1: string
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6328 this.val2: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6329 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6330 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6331 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
6332 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6333
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6334 " 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
6335 " 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
6336 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
6337 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
6338 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6339
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6340 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
6341 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
6342 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
6343 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
6344 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6345 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6346 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6347 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6348
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6349 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
6350 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
6351 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6352 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
6353 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
6354 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6355 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6356 this.var3 = [{c: 30}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6357 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6358
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6359 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
6360 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
6361 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6362 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
6363 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
6364 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6365 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6366 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6367 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6368
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6369 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
6370 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
6371 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6372 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
6373 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
6374 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6375 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6376 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6377 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6378
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6379 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
6380 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
6381 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
6382 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
6383 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
6384 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
6385 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
6386 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6387
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6388 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
6389 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
6390 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
6391 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
6392 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
6393 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
6394 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
6395 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
6396 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6397 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
6398
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6399 # 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
6400 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
6401 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6402
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6403 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
6404 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
6405 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
6406 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
6407 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6408
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6409 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
6410 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
6411 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6412 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6413
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6414 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
6415 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
6416 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6417 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
6418 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6419 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6420
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6421 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
6422 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
6423 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6424 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
6425 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6426 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6427 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6428 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
6429
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6430 # 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
6431 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
6432 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6433
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6434 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
6435 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
6436 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
6437 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
6438 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6439
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6440 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
6441 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
6442 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
6443 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6444 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
6445 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6446 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6447
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6448 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
6449 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
6450 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6451 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
6452 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6453 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6454
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6455 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
6456 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
6457 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6458 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
6459 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6460 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6461 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6462 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
6463
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6464 # 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
6465 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
6466 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6467
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6468 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
6469 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6470 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6471 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6472 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6473
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6474 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
6475 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6476 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6477
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6478 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
6479 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6480 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6481 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6482
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6483 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
6484 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6485 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6486 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6487 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6488 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
6489
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6490 # 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
6491 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
6492 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6493
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6494 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
6495 this.var1: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6496 this.var2: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6497 this.var3: list<dict<number>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6498 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6499
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6500 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
6501 this.v1: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6502 this.var3: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6503 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6504
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6505 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
6506 this.v2: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6507 this.var2 = [{b: 20}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6508 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6509
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6510 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
6511 this.v3: list<list<number>> = [[0]]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6512 this.var1 = [{a: 10}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6513 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6514 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6515 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
6516 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6517
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6518 " 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
6519 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
6520 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
6521 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6522 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
6523 this.n1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6524 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
6525 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6526 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
6527 this.n2: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6528 this.n1: number
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6529 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
6530 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
6531 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6532 class C implements B
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6533 this.n1 = 10
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6534 this.n2 = 20
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6535 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
6536 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
6537 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6538 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
6539 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
6540 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6541 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6542 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
6543 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
6544 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
6545 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6546 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
6547 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
6548 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
6549 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
6550 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
6551 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6552 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
6553 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
6554 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
6555 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6556 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
6557 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6558
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6559 " 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
6560 " 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
6561 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
6562 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
6563 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6564 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
6565 this.val: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6566 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6567 class 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
6568 this.val = [{a: '1'}, {b: '2'}]
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6569 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6570 var 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
6571 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
6572 END
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6573 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
6574
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6575 # 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
6576 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
6577 vim9script
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6578 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
6579 this.val: list<dict<string>>
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6580 endinterface
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6581 class 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
6582 this.val = {a: 1, b: 2}
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6583 endclass
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6584 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
6585 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6586 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
6587 enddef
b5ed566262d3 patch 9.0.1906: Vim9: Interfaces should not support class methods and variables
Christian Brabandt <cb@256bit.org>
parents: 33260
diff changeset
6588
33286
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6589 " 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
6590 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
6591 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
6592 vim9script
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6593
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6594 class 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
6595 this.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
6596 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6597
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6598 class 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
6599 this.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
6600 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6601
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6602 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
6603 this.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
6604 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6605
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6606 class 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
6607 this.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
6608 endclass
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6609
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6610 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
6611 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
6612 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6613
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6614 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
6615 T(d)
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6616 END
33385
b5ad84fdc702 patch 9.0.1951: Vim9: hard to debug vim9_class errors from CI
Christian Brabandt <cb@256bit.org>
parents: 33381
diff changeset
6617 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
6618 enddef
0c3553cfe22e patch 9.0.1909: Vim9: problem calling class method from other class
Christian Brabandt <cb@256bit.org>
parents: 33278
diff changeset
6619
33297
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6620 " 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
6621 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
6622 # 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
6623 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
6624 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6625
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6626 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6627 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6628 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
6629 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6630 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6631
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6632 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6633 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6634 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6635 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
6636
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6637 # 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
6638 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6639 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6640
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6641 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6642 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6643 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
6644 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6645 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6646
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6647 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6648 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6649 o.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6650 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6651 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6652 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6653 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
6654
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6655 # 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
6656 # script context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6657 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6658 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6659
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6660 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6661 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6662 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
6663 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6664
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6665 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
6666 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
6667 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6668 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6669 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6670
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6671 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6672 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6673 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6674 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
6675
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6676 # 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
6677 # def function context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6678 lines =<< trim END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6679 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6680
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6681 class C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6682 def Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6683 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
6684 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6685
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6686 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
6687 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
6688 o_typed.Foo()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6689 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6690 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6691
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6692 def T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6693 var o: C
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6694 C.Bar(o)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6695 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6696 T()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6697 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6698 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
6699 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6700
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6701 " 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
6702 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
6703 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
6704 vim9script
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6705
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6706 class Context
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6707 public this.state: dict<number> = {}
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6708 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
6709 return this.state
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6710 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6711 endclass
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6712
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6713 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
6714 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
6715 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
6716 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
6717
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6718 def F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6719 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
6720 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
6721 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6722 F()
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6723 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
6724 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
6725 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
6726 END
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6727 v9.CheckSourceSuccess(lines)
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6728 enddef
6340c608ca54 patch 9.0.1914: Vim9: few issues when accessing object members
Christian Brabandt <cb@256bit.org>
parents: 33291
diff changeset
6729
33337
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6730 " 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
6731 " 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
6732 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
6733 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
6734 vim9script
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6735
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6736 class Context
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6737 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6738
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6739 class Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6740 endclass
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6741
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6742 def Failure(): Result
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6743 return Result.new()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6744 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6745
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6746 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
6747 return Failure()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6748 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6749
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6750 def Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6751 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
6752 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
6753 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6754
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6755 Test_GetResult()
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6756 END
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6757 v9.CheckSourceSuccess(lines)
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6758 enddef
19b4f85c2649 patch 9.0.1932: Vim9: error when using null object constructor
Christian Brabandt <cb@256bit.org>
parents: 33326
diff changeset
6759
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6760 " 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
6761 def Test_duplicate_variable()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6762 # 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
6763 var lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6764 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6765 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6766 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6767 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6768 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6769 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6770 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6771 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
6772
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6773 # 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
6774 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6775 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6776 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6777 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6778 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6779 def F1()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6780 echo this.sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6781 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6782 static def F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6783 echo sval
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6784 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6785 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6786 A.F2()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6787 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6788 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
6789
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6790 # 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
6791 lines =<< trim END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6792 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6793 class A
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6794 public static sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6795 public this.sval: number
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6796 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6797 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6798 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6799 var a = A.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6800 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6801 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
6802 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6803
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6804 " 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
6805 def Test_reserved_varname()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6806 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
6807 '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
6808 '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
6809
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6810 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
6811 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6812 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6813 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6814 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6815 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6816 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6817 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
6818
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6819 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6820 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6821 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6822 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6823 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6824 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6825 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6826 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6827 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6828 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
6829
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6830 lines =<< trim eval END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6831 vim9script
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6832 class C
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6833 public this.{kword}: list<number> = [1, 2, 3]
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6834 def new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6835 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6836 def F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6837 echo this.{kword}
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6838 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6839 endclass
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6840 var o = C.new()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6841 o.F()
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6842 END
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6843 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
6844
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6845 # 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
6846 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
6847 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
6848 vim9script
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6849 class C
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6850 public static {kword}: list<number> = [1, 2, 3]
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6851 endclass
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6852 END
f61713271934 patch 9.0.2002: Vim9: need cleanup of class related interface code
Christian Brabandt <cb@256bit.org>
parents: 33503
diff changeset
6853 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
6854 endif
33381
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6855 endfor
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6856 enddef
17301c641749 patch 9.0.1949: Vim9: allows reserved keywords as members
Christian Brabandt <cb@256bit.org>
parents: 33379
diff changeset
6857
33401
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6858 " 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
6859 " 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
6860 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
6861 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
6862 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6863
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6864 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6865 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6866 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
6867 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6868 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
6869 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6870
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6871 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6872 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
6873 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6874 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6875 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6876
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6877 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
6878 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
6879 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6880 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6881 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6882 END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6883 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
6884
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6885 lines =<< trim END
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6886 vim9script
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6887
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6888 class A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6889 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6890 class B extends A
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6891 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6892 class C extends B
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6893 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6894
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6895 class Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6896 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
6897 return B.new()
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6898 enddef
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6899 endclass
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6900
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6901 class Bar extends Foo
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6902 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
6903 return C.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6904 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6905 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6906 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6907 v9.CheckSourceSuccess(lines)
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6908
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6909 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6910 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6911
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6912 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6913 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6914 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
6915 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6916 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
6917 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6918
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6919 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6920 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
6921 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6922 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6923 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6924
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6925 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
6926 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
6927 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6928 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6929 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6930 END
33432
97ceabebaeaf patch 9.0.1974: vim9: using contra-variant type-checks
Christian Brabandt <cb@256bit.org>
parents: 33401
diff changeset
6931 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
6932
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6933 lines =<< trim END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6934 vim9script
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6935
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6936 class A
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6937 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6938 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
6939 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6940 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
6941 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6942
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6943 class Foo
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6944 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
6945 return B.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6946 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6947 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6948
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6949 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
6950 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
6951 return A.new()
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6952 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6953 endclass
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6954 END
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6955 v9.CheckSourceFailure(lines, 'E1383: Method "Doit": type mismatch, expected func(object<B>): object<B> but got func(object<B>): object<A>', 20)
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6956 enddef
bb99820510ef patch 9.0.1959: Vim9: methods parameters and types are covariant
Christian Brabandt <cb@256bit.org>
parents: 33393
diff changeset
6957
33446
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6958 " 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
6959 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
6960 " 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
6961 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6962 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6963 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6964 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
6965 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6966 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6967 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6968 public static 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
6969 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6970 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6971 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6972 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6973 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
6974
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6975 " 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
6976 " class def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6977 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6978 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6979 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
6980 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6981 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6982 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6983 public static 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
6984 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6985 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6986 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6987 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6988 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6989 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6990 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6991 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6992 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
6993
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6994 " 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
6995 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6996 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
6997 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
6998 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
6999 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7000 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7001 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7002 public static 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
7003 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7004 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7005 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7006 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7007 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7008 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7009 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7010 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
7011
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7012 " 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
7013 " 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
7014 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7015 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7016 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
7017 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7018 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7019 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7020 public static Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7021 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7022 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7023 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7024 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7025 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
7026
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7027 " 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
7028 " 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
7029 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7030 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7031 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
7032 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7033 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7034 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7035 public static Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7036 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7037 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7038 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7039 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7040 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7041 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7042 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7043 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7044 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
7045
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7046 " 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
7047 " 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
7048 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7049 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7050 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
7051 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7052 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7053 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7054 public static Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7055 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7056 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7057 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7058 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7059 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7060 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7061 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7062 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
7063
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7064 " 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
7065 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7066 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7067 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
7068 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7069 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7070 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7071 public static Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7072 public static Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7073 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7074 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
7075 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
7076 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7077 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7078 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
7079 A.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7080 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
7081 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
7082 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7083 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7084 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
7085 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7086 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7087
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7088 " 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
7089 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7090 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7091 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
7092 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7093 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7094 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7095 public static Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7096 public static Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7097
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7098 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
7099 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
7100 Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7101 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
7102 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
7103 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
7104 Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7105 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
7106 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7107 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7108 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7109 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7110 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7111 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7112 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7113 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7114 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7115 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7116
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7117 " 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
7118 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7119 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7120 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
7121 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7122 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7123 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7124 public static Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7125 public static Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7126 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7127
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7128 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
7129 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
7130 A.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7131 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
7132 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
7133 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
7134 A.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7135 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
7136 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7137 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7138 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7139 A.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7140 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7141 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7142 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
7143
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7144 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
7145 vim9script
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7146 class A
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7147 public static foo = [0z10, 0z20]
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7148 endclass
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7149 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
7150 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
7151 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
7152 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
7153 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
7154 END
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7155 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
7156 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7157
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7158 " 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
7159 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
7160 " 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
7161 " script level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7162 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7163 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7164 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
7165 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7166 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7167 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7168 public this.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
7169 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7170 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7171 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7172 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7173 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7174 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
7175
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7176 " 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
7177 " object def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7178 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7179 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7180 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
7181 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7182 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7183 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7184 public this.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
7185 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7186 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7187 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7188 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7189 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7190 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7191 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7192 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7193 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7194 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
7195
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7196 " 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
7197 " script def method level.
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7198 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7199 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7200 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
7201 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7202 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7203 class A
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7204 public this.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
7205 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7206 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7207 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7208 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7209 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7210 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7211 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7212 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7213 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7214 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
7215
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7216 " 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
7217 " 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
7218 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7219 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7220 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
7221 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7222 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7223 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7224 public this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7225 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7226 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7227 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7228 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7229 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7230 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
7231
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7232 " 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
7233 " 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
7234 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7235 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7236 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
7237 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7238 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7239 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7240 public this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7241 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7242 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7243 this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7244 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7245 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7246 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7247 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7248 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7249 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7250 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
7251
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7252 " 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
7253 " 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
7254 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7255 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7256 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
7257 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7258 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7259 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7260 public this.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7261 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7262 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7263 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7264 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7265 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7266 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7267 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7268 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7269 END
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7270 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
7271
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7272 " 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
7273 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7274 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7275 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
7276 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7277 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7278 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7279 public this.Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7280 public this.Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7281 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7282
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7283 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7284 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
7285 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
7286 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7287 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7288 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
7289 a.Fn2 = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7290 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
7291 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
7292 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7293 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7294 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
7295 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7296 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7297
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7298 " 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
7299 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7300 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7301 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
7302 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7303 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7304 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7305 public this.Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7306 public this.Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7307
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7308 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
7309 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
7310 this.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7311 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
7312 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
7313 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
7314 this.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7315 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
7316 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7317 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7318
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7319 var a = A.new()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7320 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7321 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7322 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7323 a.Fn = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7324 a.Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7325 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7326 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7327
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7328 " 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
7329 let lines =<< trim END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7330 vim9script
33471
baa62f464436 patch 9.0.1988: Vim9: potential use-after-free for class members
Christian Brabandt <cb@256bit.org>
parents: 33456
diff changeset
7331 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
7332 return {}
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7333 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7334 class A
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7335 public this.Fn: any = Foo
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7336 public this.Fn2: any
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7337 endclass
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7338
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7339 def Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7340 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
7341 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
7342 a.Fn = "abc"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7343 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
7344 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
7345 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
7346 a.Fn2 = "xyz"
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7347 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
7348 enddef
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7349 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7350 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7351 test_garbagecollect_now()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7352 Bar()
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7353 END
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7354 call v9.CheckSourceSuccess(lines)
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7355 endfunc
508dfc0c261c patch 9.0.1977: Vim9: object members can change type
Christian Brabandt <cb@256bit.org>
parents: 33432
diff changeset
7356
33501
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7357 " 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
7358 " 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
7359 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
7360 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
7361 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7362 class A
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7363 this.val: number = 0
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7364 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
7365 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
7366 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
7367 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7368 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
7369 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
7370 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7371 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7372 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
7373 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
7374 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7375 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
7376 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7377
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7378 " 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
7379 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
7380 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
7381 vim9script
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7382 class A
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7383 static val: number = 0
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7384 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
7385 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
7386 return val
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7387 endif
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7388 val += 1
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7389 return Foo()
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7390 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7391 endclass
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7392 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
7393 END
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7394 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
7395 enddef
c7c630759e31 patch 9.0.2000: Vim9: use-after-free in deep call stack
Christian Brabandt <cb@256bit.org>
parents: 33498
diff changeset
7396
33517
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7397 " 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
7398 " 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
7399 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
7400 var lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7401 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7402 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7403 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7404 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7405 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7406
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7407 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7408 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7409 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7410
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7411 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
7412 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7413 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
7414
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7415 lines =<< trim END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7416 vim9script
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7417 class A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7418 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7419 class B extends A
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7420 endclass
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7421
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7422 def Foo(p: B): B
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7423 return B.new()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7424 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7425
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7426 def Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7427 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
7428 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7429 Baz()
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7430 END
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7431 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
7432 enddef
921673b465a6 patch 9.0.2007: Vim9: covariant parameter types allowed
Christian Brabandt <cb@256bit.org>
parents: 33506
diff changeset
7433
33534
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7434 " 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
7435 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
7436 # 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
7437 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
7438 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7439 class A
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7440 public static val: 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
7441 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
7442 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
7443 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
7444 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7445 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7446 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
7447 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
7448 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
7449 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7450 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
7451 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
7452 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
7453 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
7454 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7455 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
7456
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7457 # 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
7458 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
7459 vim9script
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7460 class A
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7461 public this.val: 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
7462 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
7463 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
7464 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
7465 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7466 endclass
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7467 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
7468 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
7469 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
7470 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7471 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
7472 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
7473 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
7474 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
7475 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
7476 END
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7477 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
7478 enddef
c8bd88bdb630 patch 9.0.2016: Vim9: assignment operators don't work for class vars
Christian Brabandt <cb@256bit.org>
parents: 33532
diff changeset
7479
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7480 " 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
7481 def Test_object_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7482 # 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
7483 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7484 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7485 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7486 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7487 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7488 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7489 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7490 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7491 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7492 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7493 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
7494 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7495 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7496 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7497 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7498
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7499 # 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
7500 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7501 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7502 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7503 def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7504 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7505 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7506 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7507 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7508 var Fn = a.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7509 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
7510 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7511 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7512
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7513 # 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
7514 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7515 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7516 class A
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7517 this.val: number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7518 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7519 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7520 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7521 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7522 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
7523 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
7524 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
7525 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7526 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7527
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7528 # 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
7529 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7530 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7531 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7532 def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7533 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7534 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7535 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7536 var Fn = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7537 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
7538 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7539 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7540 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7541 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7542 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7543 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7544
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7545 # 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
7546 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7547 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7548 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7549 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
7550 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7551 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7552 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7553 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7554 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
7555 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
7556 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7557 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7558
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7559 # 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
7560 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7561 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7562 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7563
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7564 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
7565 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7566 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7567
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7568 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7569 def Double(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7570 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7571 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7572 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7573
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7574 const math = Math.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7575 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
7576 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7577 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7578
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7579 # Try using a private 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
7580 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7581 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7582 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7583 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7584 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7585 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7586 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7587 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7588 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7589 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7590 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7591 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7592 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 2)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7593
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7594 # Try using a private 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
7595 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7596 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7597 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7598 def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7599 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7600 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7601 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7602 var Fn = a._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7603 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7604 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 7)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7605
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7606 # Using a private 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
7607 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7608 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7609 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7610 def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7611 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7612 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7613 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7614 var Fn = this._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7615 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
7616 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7617 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7618 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7619 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7620 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7621 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
7622
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7623 # 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
7624 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7625 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7626 class A
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7627 this.val: number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7628 def Foo(): number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7629 return this.val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7630 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7631 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7632
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7633 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
7634 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
7635 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7636
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7637 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
7638 Bar(a)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7639 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
7640 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7641 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7642 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7643
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7644 " 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
7645 def Test_class_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7646 # 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
7647 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7648 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7649 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7650 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7651 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7652 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7653 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7654 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7655 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7656 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
7657 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7658 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7659 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7660 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7661
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7662 # 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
7663 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7664 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7665 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7666 static def Foo(): dict<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7667 return {a: 1, b: 2}
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7668 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7669 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7670 var Fn = A.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7671 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
7672 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7673 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7674
33568
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7675 # 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
7676 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7677 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7678 class A
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7679 public static val: number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7680 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
7681 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7682 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7683 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7684 A.val = 567
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7685 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
7686 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
7687 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7688 v9.CheckSourceSuccess(lines)
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7689
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7690 # 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
7691 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7692 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7693 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7694 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
7695 return l
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7696 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7697 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7698 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
7699 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
7700 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7701 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7702
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7703 # 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
7704 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7705 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7706 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7707 static def Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7708 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7709 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7710 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7711 var Fn = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7712 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
7713 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7714 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7715 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7716 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7717 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7718
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7719 # 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
7720 # funcref.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7721 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7722 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7723
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7724 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
7725 return (n: number) => F(n)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7726 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7727
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7728 class Math
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7729 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
7730 return 2 * n
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7731 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7732 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7733
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7734 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
7735 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7736 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7737
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7738 # Try using a private 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
7739 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7740 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7741 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7742 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7743 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7744 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7745 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7746 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7747 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7748 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7749 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7750 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 1)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7751
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7752 # Try using a private 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
7753 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7754 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7755 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7756 static def _Foo()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7757 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7758 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7759 var Fn = A._Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7760 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7761 v9.CheckSourceFailure(lines, 'E1366: Cannot access private method: _Foo', 6)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7762
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7763 # Using a private 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
7764 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7765 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7766 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7767 static def _Foo(): list<number>
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7768 return [3, 2, 1]
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7769 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7770 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7771 var Fn = _Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7772 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
7773 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7774 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7775 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7776 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7777 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
7778
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7779 # 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
7780 lines =<< trim END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7781 vim9script
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7782 class A
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7783 public static val: number
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7784 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
7785 return val
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7786 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7787 endclass
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7788
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7789 def Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7790 A.val = 468
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7791 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
7792 enddef
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7793 Bar()
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7794 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
7795 END
4db948057fa6 patch 9.0.2029: Vim9: no support for partials using call()
Christian Brabandt <cb@256bit.org>
parents: 33540
diff changeset
7796 v9.CheckSourceSuccess(lines)
33540
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7797 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7798
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7799 " 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
7800 def Test_object_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7801 # 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
7802 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7803 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7804 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7805 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7806 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7807
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7808 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7809 this.Cb: func(number): number = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7810 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7811 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
7812 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7813 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7814
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7815 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7816 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7817 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7818 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7819
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7820 # 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
7821 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7822 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7823 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7824 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7825 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7826
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7827 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7828 this.Cb: func(number): number = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7829 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7830
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7831 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7832 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7833 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
7834 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7835 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7836 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7837 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7838
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7839 # 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
7840 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7841 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7842 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7843 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7844 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7845
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7846 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7847 this.Cb: func(number): number = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7848 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7849
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7850 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7851 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
7852 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7853 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7854
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7855 # 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
7856 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7857 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7858 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7859 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7860 this.Cb: func(number): number = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7861 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7862 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7863 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7864 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7865 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
7866 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7867 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7868
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7869 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7870 a.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7871 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7872 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7873
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7874 # 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
7875 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7876 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7877 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7878 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7879 this.Cb: func(number): number = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7880 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7881 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7882 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7883 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7884
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7885 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7886 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7887 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
7888 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7889 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7890 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7891 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7892
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7893 # 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
7894 # level.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7895 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7896 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7897 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7898 this.Cb = this.Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7899 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7900 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7901 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7902 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7903
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7904 var a = A.new()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7905 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
7906 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7907 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7908 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7909
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7910 " 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
7911 def Test_class_member_funcref()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7912 # 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
7913 var lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7914 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7915 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7916 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7917 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7918
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7919 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7920 static Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7921 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7922 assert_equal(200, Cb(20))
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7923 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7924 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7925
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7926 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7927 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7928 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7929
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7930 # 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
7931 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7932 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7933 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7934 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7935 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7936
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7937 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7938 public static Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7939 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7940
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7941 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7942 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
7943 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7944 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7945 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7946 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7947
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7948 # 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
7949 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7950 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7951 def Foo(n: number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7952 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7953 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7954
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7955 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7956 public static Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7957 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7958
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7959 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
7960 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7961 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7962
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7963 # 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
7964 # method.
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7965 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7966 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7967 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7968 static Cb: func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7969 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
7970 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7971 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7972 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7973 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7974 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7975 static def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7976 assert_equal(200, Cb(20))
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 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7979
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7980 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7981 A.Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7982 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7983 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7984
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7985 # 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
7986 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7987 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7988 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7989 static Cb: func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7990 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
7991 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7992 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7993 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7994 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7995 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7996 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7997
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7998 def Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
7999 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8000 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
8001 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8002 Bar()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8003 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8004 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8005
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8006 # 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
8007 lines =<< trim END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8008 vim9script
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8009 class A
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8010 static Cb: func(number): number
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8011 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
8012 return n * 10
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8013 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8014 static def Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8015 Cb = Foo
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8016 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8017 endclass
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8018
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8019 A.Init()
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8020 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
8021 END
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8022 v9.CheckSourceSuccess(lines)
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8023 enddef
86dbcbb94fdb patch 9.0.2019: Vim9: no support for funcrefs
Christian Brabandt <cb@256bit.org>
parents: 33534
diff changeset
8024
32670
695b50472e85 Fix line endings issue
Christian Brabandt <cb@256bit.org>
parents: 32669
diff changeset
8025 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker