annotate src/testdir/test_vim9_class.vim @ 31720:1949c2613b3e v9.0.1192

patch 9.0.1192: no error when class function argument shadows a member Commit: https://github.com/vim/vim/commit/d40f00cb43019fb4d39b89f407f8b52e92f9e16f Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jan 13 17:36:49 2023 +0000 patch 9.0.1192: no error when class function argument shadows a member Problem: No error when class function argument shadows a member. Solution: Check for shadowing.
author Bram Moolenaar <Bram@vim.org>
date Fri, 13 Jan 2023 18:45:03 +0100
parents 2d68375d5ddf
children ef7a9a7eb197
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Test Vim9 classes
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 source check.vim
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 import './vim9.vim' as v9
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 def Test_class_basic()
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 var lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 class NotWorking
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 v9.CheckScriptFailure(lines, 'E1316:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 class notWorking
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 v9.CheckScriptFailure(lines, 'E1314:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 class Not@working
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 v9.CheckScriptFailure(lines, 'E1315:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 abstract noclass Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 v9.CheckScriptFailure(lines, 'E475:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 abstract classy Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 v9.CheckScriptFailure(lines, 'E475:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 endcl
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 v9.CheckScriptFailure(lines, 'E1065:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 endclass school's out
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 v9.CheckScriptFailure(lines, 'E488:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 endclass | echo 'done'
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 v9.CheckScriptFailure(lines, 'E488:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 this
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 this.
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 this .count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 this. count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 v9.CheckScriptFailure(lines, 'E1317:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 this.count: number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 that.count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 v9.CheckScriptFailure(lines, 'E1318: Not a valid command in a class: that.count')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 this.count
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 v9.CheckScriptFailure(lines, 'E1022:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 class Something
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
114 def new()
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
115 this.state = 0
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
116 enddef
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
117 endclass
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
118 var obj = Something.new()
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
119 END
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
120 v9.CheckScriptFailure(lines, 'E1089:')
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
121
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
122 lines =<< trim END
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
123 vim9script
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
124 class Something
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 this.count : number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 v9.CheckScriptFailure(lines, 'E1059:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 class Something
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 this.count:number
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 v9.CheckScriptFailure(lines, 'E1069:')
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 lines =<< trim END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 vim9script
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 class TextPosition
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 this.lnum: number
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
143 this.col: number
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
144
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
145 # make a nicely formatted string
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
146 def ToString(): string
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
147 return $'({this.lnum}, {this.col})'
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
148 enddef
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 endclass
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150
31404
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
151 # use the automatically generated new() method
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
152 var pos = TextPosition.new(2, 12)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
153 assert_equal(2, pos.lnum)
60b1d266548d patch 9.0.1035: object members are not being marked as used
Bram Moolenaar <Bram@vim.org>
parents: 31396
diff changeset
154 assert_equal(12, pos.col)
31416
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
155
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
156 # call an object method
f088f1d97eee patch 9.0.1041: cannot define a method in a class
Bram Moolenaar <Bram@vim.org>
parents: 31404
diff changeset
157 assert_equal('(2, 12)', pos.ToString())
31712
2d68375d5ddf patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents: 31708
diff changeset
158
2d68375d5ddf patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents: 31708
diff changeset
159 assert_equal(v:t_class, type(TextPosition))
2d68375d5ddf patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents: 31708
diff changeset
160 assert_equal(v:t_object, type(pos))
2d68375d5ddf patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents: 31708
diff changeset
161 assert_equal('class<TextPosition>', typename(TextPosition))
2d68375d5ddf patch 9.0.1188: return value of type() for class and object unclear
Bram Moolenaar <Bram@vim.org>
parents: 31708
diff changeset
162 assert_equal('object<TextPosition>', typename(pos))
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 END
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 v9.CheckScriptSuccess(lines)
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 enddef
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
167 def Test_class_member_initializer()
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
168 var lines =<< trim END
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
169 vim9script
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
170
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
171 class TextPosition
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
172 this.lnum: number = 1
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
173 this.col: number = 1
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
174
31501
560ba934725f patch 9.0.1083: empty and comment lines in a class cause an error
Bram Moolenaar <Bram@vim.org>
parents: 31483
diff changeset
175 # constructor with only the line number
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
176 def new(lnum: number)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
177 this.lnum = lnum
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
178 enddef
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
179 endclass
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
180
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
181 var pos = TextPosition.new(3)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
182 assert_equal(3, pos.lnum)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
183 assert_equal(1, pos.col)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
184
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
185 var instr = execute('disassemble TextPosition.new')
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
186 assert_match('new\_s*' ..
31426
92afb904fbee patch 9.0.1046: class method disassemble test fails on MS-Windows
Bram Moolenaar <Bram@vim.org>
parents: 31424
diff changeset
187 '0 NEW TextPosition size \d\+\_s*' ..
31424
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
188 '\d PUSHNR 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
189 '\d STORE_THIS 0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
190 '\d PUSHNR 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
191 '\d STORE_THIS 1\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
192 'this.lnum = lnum\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
193 '\d LOAD arg\[-1]\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
194 '\d PUSHNR 0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
195 '\d LOAD $0\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
196 '\d\+ STOREINDEX object\_s*' ..
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
197 '\d\+ RETURN object.*',
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
198 instr)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
199 END
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
200 v9.CheckScriptSuccess(lines)
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
201 enddef
e31fc75f6aff patch 9.0.1045: in a class object members cannot be initialized
Bram Moolenaar <Bram@vim.org>
parents: 31416
diff changeset
202
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
203 def Test_class_default_new()
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
204 var lines =<< trim END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
205 vim9script
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
206
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
207 class TextPosition
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
208 this.lnum: number = 1
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
209 this.col: number = 1
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
210 endclass
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
211
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
212 var pos = TextPosition.new()
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
213 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
214 assert_equal(1, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
215
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
216 pos = TextPosition.new(v:none, v:none)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
217 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
218 assert_equal(1, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
219
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
220 pos = TextPosition.new(3, 22)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
221 assert_equal(3, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
222 assert_equal(22, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
223
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
224 pos = TextPosition.new(v:none, 33)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
225 assert_equal(1, pos.lnum)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
226 assert_equal(33, pos.col)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
227 END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
228 v9.CheckScriptSuccess(lines)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
229
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
230 lines =<< trim END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
231 vim9script
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
232 class Person
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
233 this.name: string
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
234 this.age: number = 42
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
235 this.education: string = "unknown"
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
236
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
237 def new(this.name, this.age = v:none, this.education = v:none)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
238 enddef
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
239 endclass
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
240
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
241 var piet = Person.new("Piet")
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
242 assert_equal("Piet", piet.name)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
243 assert_equal(42, piet.age)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
244 assert_equal("unknown", piet.education)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
245
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
246 var chris = Person.new("Chris", 4, "none")
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
247 assert_equal("Chris", chris.name)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
248 assert_equal(4, chris.age)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
249 assert_equal("none", chris.education)
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
250 END
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
251 v9.CheckScriptSuccess(lines)
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
252
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
253 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
254 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
255 class Person
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
256 this.name: string
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
257 this.age: number = 42
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
258 this.education: string = "unknown"
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
259
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
260 def new(this.name, this.age = v:none, this.education = v:none)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
261 enddef
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
262 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
263
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
264 var missing = Person.new()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
265 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
266 v9.CheckScriptFailure(lines, 'E119:')
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
267 enddef
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
268
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
269 def Test_class_object_member_inits()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
270 var lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
271 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
272 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
273 this.lnum: number
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
274 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
275 this.addcol: number = 2
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
276 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
277
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
278 var pos = TextPosition.new()
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
279 assert_equal(0, pos.lnum)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
280 assert_equal(1, pos.col)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
281 assert_equal(2, pos.addcol)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
282 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
283 v9.CheckScriptSuccess(lines)
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
284
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
285 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
286 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
287 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
288 this.lnum
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
289 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
290 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
291 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
292 v9.CheckScriptFailure(lines, 'E1022:')
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
293
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
294 lines =<< trim END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
295 vim9script
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
296 class TextPosition
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
297 this.lnum = v:none
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
298 this.col = 1
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
299 endclass
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
300 END
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
301 v9.CheckScriptFailure(lines, 'E1330:')
31441
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
302 enddef
e572ff386670 patch 9.0.1053: default constructor arguments are not optional
Bram Moolenaar <Bram@vim.org>
parents: 31426
diff changeset
303
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
304 def Test_class_object_member_access()
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
305 var lines =<< trim END
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
306 vim9script
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
307 class Triple
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
308 this._one = 1
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
309 this.two = 2
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
310 public this.three = 3
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
311
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
312 def GetOne(): number
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
313 return this._one
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
314 enddef
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
315 endclass
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
316
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
317 var trip = Triple.new()
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
318 assert_equal(1, trip.GetOne())
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
319 assert_equal(2, trip.two)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
320 assert_equal(3, trip.three)
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
321 assert_fails('echo trip._one', 'E1333')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
322
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
323 assert_fails('trip._one = 11', 'E1333')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
324 assert_fails('trip.two = 22', 'E1335')
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
325 trip.three = 33
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
326 assert_equal(33, trip.three)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
327
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
328 assert_fails('trip.four = 4', 'E1334')
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
329 END
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
330 v9.CheckScriptSuccess(lines)
31521
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
331
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
332 lines =<< trim END
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
333 vim9script
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
334
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
335 class MyCar
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
336 this.make: string
31616
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
337 this.age = 5
31521
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
338
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
339 def new(make_arg: string)
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
340 this.make = make_arg
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
341 enddef
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
342
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
343 def GetMake(): string
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
344 return $"make = {this.make}"
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
345 enddef
31616
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
346 def GetAge(): number
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
347 return this.age
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
348 enddef
31521
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
349 endclass
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
350
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
351 var c = MyCar.new("abc")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
352 assert_equal('make = abc', c.GetMake())
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
353
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
354 c = MyCar.new("def")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
355 assert_equal('make = def', c.GetMake())
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
356
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
357 var c2 = MyCar.new("123")
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
358 assert_equal('make = 123', c2.GetMake())
31616
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
359
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
360 def CheckCar()
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
361 assert_equal("make = def", c.GetMake())
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
362 assert_equal(5, c.GetAge())
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
363 enddef
0eb51cec2154 patch 9.0.1140: cannot call an object method in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31614
diff changeset
364 CheckCar()
31521
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
365 END
065e4ccf5e10 patch 9.0.1093: using freed memory of object member
Bram Moolenaar <Bram@vim.org>
parents: 31517
diff changeset
366 v9.CheckScriptSuccess(lines)
31525
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
367
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
368 lines =<< trim END
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
369 vim9script
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
370
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
371 class MyCar
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
372 this.make: string
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
373
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
374 def new(make_arg: string)
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
375 this.make = make_arg
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
376 enddef
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
377 endclass
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
378
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
379 var c = MyCar.new("abc")
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
380 var c = MyCar.new("def")
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
381 END
f7c82a85e88a patch 9.0.1095: using freed memory when declaration fails
Bram Moolenaar <Bram@vim.org>
parents: 31521
diff changeset
382 v9.CheckScriptFailure(lines, 'E1041:')
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
383 enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
384
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
385 def Test_class_object_compare()
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
386 var class_lines =<< trim END
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
387 vim9script
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
388 class Item
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
389 this.nr = 0
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
390 this.name = 'xx'
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
391 endclass
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
392 END
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
393
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
394 # used at the script level and in a compiled function
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
395 var test_lines =<< trim END
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
396 var i1 = Item.new()
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
397 assert_equal(i1, i1)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
398 assert_true(i1 is i1)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
399 var i2 = Item.new()
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
400 assert_equal(i1, i2)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
401 assert_false(i1 is i2)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
402 var i3 = Item.new(0, 'xx')
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
403 assert_equal(i1, i3)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
404
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
405 var io1 = Item.new(1, 'xx')
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
406 assert_notequal(i1, io1)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
407 var io2 = Item.new(0, 'yy')
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
408 assert_notequal(i1, io2)
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
409 END
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
410
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
411 v9.CheckScriptSuccess(class_lines + test_lines)
31614
f3c7e573b7be patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
412 v9.CheckScriptSuccess(
f3c7e573b7be patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
413 class_lines + ['def Test()'] + test_lines + ['enddef', 'Test()'])
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
414
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
415 for op in ['>', '>=', '<', '<=', '=~', '!~']
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
416 var op_lines = [
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
417 'var i1 = Item.new()',
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
418 'var i2 = Item.new()',
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
419 'echo i1 ' .. op .. ' i2',
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
420 ]
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
421 v9.CheckScriptFailure(class_lines + op_lines, 'E1153: Invalid operation for object')
31614
f3c7e573b7be patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
422 v9.CheckScriptFailure(class_lines
f3c7e573b7be patch 9.0.1139: cannot create a new object in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31604
diff changeset
423 + ['def Test()'] + op_lines + ['enddef', 'Test()'], 'E1153: Invalid operation for object')
31604
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
424 endfor
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
425 enddef
9b13b3a63bc0 patch 9.0.1134: comparing objects uses identity instead of equality
Bram Moolenaar <Bram@vim.org>
parents: 31590
diff changeset
426
31698
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
427 def Test_object_type()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
428 var lines =<< trim END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
429 vim9script
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
430
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
431 class One
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
432 this.one = 1
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
433 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
434 class Two
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
435 this.two = 2
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
436 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
437 class TwoMore extends Two
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
438 this.more = 9
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
439 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
440
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
441 var o: One = One.new()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
442 var t: Two = Two.new()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
443 var m: TwoMore = TwoMore.new()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
444 var tm: Two = TwoMore.new()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
445
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
446 t = m
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
447 END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
448 v9.CheckScriptSuccess(lines)
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
449
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
450 lines =<< trim END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
451 vim9script
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
452
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
453 class One
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
454 this.one = 1
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
455 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
456 class Two
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
457 this.two = 2
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
458 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
459
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
460 var o: One = Two.new()
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
461 END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
462 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<One> but got object<Two>')
31704
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
463
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
464 lines =<< trim END
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
465 vim9script
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
466
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
467 interface One
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
468 def GetMember(): number
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
469 endinterface
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
470 class Two implements One
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
471 this.one = 1
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
472 def GetMember(): number
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
473 return this.one
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
474 enddef
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
475 endclass
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
476
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
477 var o: One = Two.new(5)
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
478 assert_equal(5, o.GetMember())
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
479 END
69ee530cac28 patch 9.0.1184: interface of an object is not recognized when checking type
Bram Moolenaar <Bram@vim.org>
parents: 31698
diff changeset
480 v9.CheckScriptSuccess(lines)
31698
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
481 enddef
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
482
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
483 def Test_class_member()
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
484 # check access rules
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
485 var lines =<< trim END
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
486 vim9script
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
487 class TextPos
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
488 this.lnum = 1
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
489 this.col = 1
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
490 static counter = 0
31580
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
491 static _secret = 7
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
492 public static anybody = 42
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
493
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
494 static def AddToCounter(nr: number)
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
495 counter += nr
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
496 enddef
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
497 endclass
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
498
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
499 assert_equal(0, TextPos.counter)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
500 TextPos.AddToCounter(3)
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
501 assert_equal(3, TextPos.counter)
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
502 assert_fails('echo TextPos.noSuchMember', 'E1338:')
31630
5400eba7c3f3 patch 9.0.1147: cannot access a class member in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31616
diff changeset
503
5400eba7c3f3 patch 9.0.1147: cannot access a class member in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31616
diff changeset
504 def GetCounter(): number
5400eba7c3f3 patch 9.0.1147: cannot access a class member in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31616
diff changeset
505 return TextPos.counter
5400eba7c3f3 patch 9.0.1147: cannot access a class member in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31616
diff changeset
506 enddef
5400eba7c3f3 patch 9.0.1147: cannot access a class member in a compiled function
Bram Moolenaar <Bram@vim.org>
parents: 31616
diff changeset
507 assert_equal(3, GetCounter())
31483
1bebc2093e6b patch 9.0.1074: class members are not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 31455
diff changeset
508
31517
cd5247f4da06 patch 9.0.1091: assignment to non-existing member causes a crash
Bram Moolenaar <Bram@vim.org>
parents: 31501
diff changeset
509 assert_fails('TextPos.noSuchMember = 2', 'E1337:')
31580
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
510 assert_fails('TextPos.counter = 5', 'E1335:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
511 assert_fails('TextPos.counter += 5', 'E1335:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
512
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
513 assert_fails('echo TextPos._secret', 'E1333:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
514 assert_fails('TextPos._secret = 8', 'E1333:')
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
515
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
516 assert_equal(42, TextPos.anybody)
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
517 TextPos.anybody = 12
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
518 assert_equal(12, TextPos.anybody)
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
519 TextPos.anybody += 5
9f2a9dd57226 patch 9.0.1122: class member access is not fully tested yet
Bram Moolenaar <Bram@vim.org>
parents: 31525
diff changeset
520 assert_equal(17, TextPos.anybody)
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
521 END
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
522 v9.CheckScriptSuccess(lines)
31590
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
523
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
524 # check shadowing
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
525 lines =<< trim END
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
526 vim9script
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
527
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
528 class Some
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
529 static count = 0
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
530 def Method(count: number)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
531 echo count
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
532 enddef
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
533 endclass
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
534
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
535 var s = Some.new()
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
536 s.Method(7)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
537 END
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
538 v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
539
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
540 lines =<< trim END
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
541 vim9script
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
542
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
543 class Some
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
544 static count = 0
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
545 def Method(arg: number)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
546 var count = 3
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
547 echo arg count
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
548 enddef
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
549 endclass
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
550
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
551 var s = Some.new()
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
552 s.Method(7)
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
553 END
aee868b9229a patch 9.0.1127: no error if function argument shadows class member
Bram Moolenaar <Bram@vim.org>
parents: 31582
diff changeset
554 v9.CheckScriptFailure(lines, 'E1341: Variable already declared in the class: count')
31455
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
555 enddef
5ef28f5ff357 patch 9.0.1060: private and public object members are not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31451
diff changeset
556
31633
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
557 func Test_class_garbagecollect()
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
558 let lines =<< trim END
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
559 vim9script
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
560
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
561 class Point
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
562 this.p = [2, 3]
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
563 static pl = ['a', 'b']
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
564 static pd = {a: 'a', b: 'b'}
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
565 endclass
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
566
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
567 echo Point.pl Point.pd
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
568 call test_garbagecollect_now()
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
569 echo Point.pl Point.pd
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
570 END
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
571 call v9.CheckScriptSuccess(lines)
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
572 endfunc
d19377e0a0b4 patch 9.0.1149: class members may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 31630
diff changeset
573
31582
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
574 def Test_class_function()
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
575 var lines =<< trim END
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
576 vim9script
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
577 class Value
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
578 this.value = 0
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
579 static objects = 0
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
580
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
581 def new(v: number)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
582 this.value = v
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
583 ++objects
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
584 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
585
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
586 static def GetCount(): number
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
587 return objects
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
588 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
589 endclass
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
590
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
591 assert_equal(0, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
592 var v1 = Value.new(2)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
593 assert_equal(1, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
594 var v2 = Value.new(7)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
595 assert_equal(2, Value.GetCount())
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
596 END
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
597 v9.CheckScriptSuccess(lines)
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
598 enddef
8bbc932fbd09 patch 9.0.1123: class function not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31580
diff changeset
599
31451
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
600 def Test_class_object_to_string()
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
601 var lines =<< trim END
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
602 vim9script
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
603 class TextPosition
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
604 this.lnum = 1
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
605 this.col = 22
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
606 endclass
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
607
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
608 assert_equal("class TextPosition", string(TextPosition))
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
609
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
610 var pos = TextPosition.new()
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
611 assert_equal("object of TextPosition {lnum: 1, col: 22}", string(pos))
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
612 END
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
613 v9.CheckScriptSuccess(lines)
5804270d6e9b patch 9.0.1058: string value of class and object do not have information
Bram Moolenaar <Bram@vim.org>
parents: 31443
diff changeset
614 enddef
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
616 def Test_interface_basics()
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
617 var lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
618 vim9script
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
619 interface Something
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
620 this.value: string
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
621 static count: number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
622 def GetCount(): number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
623 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
624 END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
625 v9.CheckScriptSuccess(lines)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
626
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
627 lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
628 interface SomethingWrong
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
629 static count = 7
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
630 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
631 END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
632 v9.CheckScriptFailure(lines, 'E1342:')
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
633
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
634 lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
635 vim9script
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
636
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
637 interface Some
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
638 static count: number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
639 def Method(count: number)
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
640 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
641 END
31720
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
642 v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: count')
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
643
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
644 lines =<< trim END
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
645 vim9script
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
646
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
647 interface Some
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
648 this.value: number
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
649 def Method(value: number)
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
650 endinterface
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
651 END
1949c2613b3e patch 9.0.1192: no error when class function argument shadows a member
Bram Moolenaar <Bram@vim.org>
parents: 31712
diff changeset
652 v9.CheckScriptFailure(lines, 'E1340: Argument already declared in the class: value')
31635
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
653
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
654 lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
655 vim9script
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
656 interface somethingWrong
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
657 static count = 7
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
658 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
659 END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
660 v9.CheckScriptFailure(lines, 'E1343: Interface name must start with an uppercase letter: somethingWrong')
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
661
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
662 lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
663 vim9script
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
664 interface SomethingWrong
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
665 this.value: string
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
666 static count = 7
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
667 def GetCount(): number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
668 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
669 END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
670 v9.CheckScriptFailure(lines, 'E1344:')
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
671
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
672 lines =<< trim END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
673 vim9script
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
674 interface SomethingWrong
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
675 this.value: string
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
676 static count: number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
677 def GetCount(): number
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
678 return 5
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
679 enddef
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
680 endinterface
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
681 END
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
682 v9.CheckScriptFailure(lines, 'E1345: Not a valid command in an interface: return 5')
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
683 enddef
5c1b7a87466e patch 9.0.1150: :interface is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31633
diff changeset
684
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
685 def Test_class_implements_interface()
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
686 var lines =<< trim END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
687 vim9script
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
688
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
689 interface Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
690 static count: number
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
691 def Method(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
692 endinterface
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
693
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
694 class SomeImpl implements Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
695 static count: number
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
696 def Method(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
697 echo nr
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
698 enddef
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
699 endclass
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
700
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
701 interface Another
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
702 this.member: string
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
703 endinterface
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
704
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
705 class SomeImpl implements Some, Another
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
706 this.member = 'abc'
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
707 static count: number
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
708 def Method(nr: number)
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
709 echo nr
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
710 enddef
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
711 endclass
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
712
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
713 END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
714 v9.CheckScriptSuccess(lines)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
715
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
716 lines =<< trim END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
717 vim9script
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
718
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
719 interface Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
720 static counter: number
31649
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
721 endinterface
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
722
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
723 class SomeImpl implements Some implements Some
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
724 static count: number
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
725 endclass
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
726 END
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
727 v9.CheckScriptFailure(lines, 'E1350:')
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
728
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
729 lines =<< trim END
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
730 vim9script
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
731
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
732 interface Some
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
733 static counter: number
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
734 endinterface
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
735
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
736 class SomeImpl implements Some, Some
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
737 static count: number
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
738 endclass
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
739 END
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
740 v9.CheckScriptFailure(lines, 'E1351: Duplicate interface after "implements": Some')
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
741
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
742 lines =<< trim END
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
743 vim9script
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
744
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
745 interface Some
520857d1fda7 patch 9.0.1157: "implements" only handles one interface name
Bram Moolenaar <Bram@vim.org>
parents: 31645
diff changeset
746 static counter: number
31639
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
747 def Method(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
748 endinterface
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
749
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
750 class SomeImpl implements Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
751 static count: number
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
752 def Method(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
753 echo nr
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
754 enddef
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
755 endclass
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
756 END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
757 v9.CheckScriptFailure(lines, 'E1348: Member "counter" of interface "Some" not implemented')
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
758
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
759 lines =<< trim END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
760 vim9script
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
761
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
762 interface Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
763 static count: number
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
764 def Methods(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
765 endinterface
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
766
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
767 class SomeImpl implements Some
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
768 static count: number
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
769 def Method(nr: number)
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
770 echo nr
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
771 enddef
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
772 endclass
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
773 END
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
774 v9.CheckScriptFailure(lines, 'E1349: Function "Methods" of interface "Some" not implemented')
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
775 enddef
62237ea155d9 patch 9.0.1152: class "implements" argument not implemented
Bram Moolenaar <Bram@vim.org>
parents: 31635
diff changeset
776
31645
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
777 def Test_class_used_as_type()
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
778 var lines =<< trim END
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
779 vim9script
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
780
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
781 class Point
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
782 this.x = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
783 this.y = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
784 endclass
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
785
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
786 var p: Point
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
787 p = Point.new(2, 33)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
788 assert_equal(2, p.x)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
789 assert_equal(33, p.y)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
790 END
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
791 v9.CheckScriptSuccess(lines)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
792
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
793 lines =<< trim END
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
794 vim9script
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
795
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
796 interface HasX
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
797 this.x: number
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
798 endinterface
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
799
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
800 class Point implements HasX
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
801 this.x = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
802 this.y = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
803 endclass
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
804
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
805 var p: Point
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
806 p = Point.new(2, 33)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
807 var hx = p
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
808 assert_equal(2, hx.x)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
809 END
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
810 v9.CheckScriptSuccess(lines)
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
811
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
812 lines =<< trim END
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
813 vim9script
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
814
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
815 class Point
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
816 this.x = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
817 this.y = 0
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
818 endclass
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
819
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
820 var p: Point
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
821 p = 'text'
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
822 END
31698
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
823 v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected object<Point> but got string')
31645
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
824 enddef
fc259e8db5bf patch 9.0.1155: cannot use a class as a type
Bram Moolenaar <Bram@vim.org>
parents: 31639
diff changeset
825
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
826 def Test_class_extends()
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
827 var lines =<< trim END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
828 vim9script
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
829 class Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
830 this.one = 1
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
831 def GetOne(): number
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
832 return this.one
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
833 enddef
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
834 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
835 class Child extends Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
836 this.two = 2
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
837 def GetTotal(): number
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
838 return this.one + this.two
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
839 enddef
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
840 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
841 var o = Child.new()
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
842 assert_equal(1, o.one)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
843 assert_equal(2, o.two)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
844 assert_equal(1, o.GetOne())
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
845 assert_equal(3, o.GetTotal())
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
846 END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
847 v9.CheckScriptSuccess(lines)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
848
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
849 lines =<< trim END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
850 vim9script
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
851 class Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
852 this.one = 1
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
853 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
854 class Child extends Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
855 this.two = 2
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
856 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
857 var o = Child.new(3, 44)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
858 assert_equal(3, o.one)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
859 assert_equal(44, o.two)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
860 END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
861 v9.CheckScriptSuccess(lines)
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
862
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
863 lines =<< trim END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
864 vim9script
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
865 class Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
866 this.one = 1
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
867 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
868 class Child extends Base extends Base
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
869 this.two = 2
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
870 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
871 END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
872 v9.CheckScriptFailure(lines, 'E1352: Duplicate "extends"')
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
873
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
874 lines =<< trim END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
875 vim9script
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
876 class Child extends BaseClass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
877 this.two = 2
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
878 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
879 END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
880 v9.CheckScriptFailure(lines, 'E1353: Class name not found: BaseClass')
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
881
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
882 lines =<< trim END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
883 vim9script
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
884 var SomeVar = 99
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
885 class Child extends SomeVar
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
886 this.two = 2
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
887 endclass
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
888 END
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
889 v9.CheckScriptFailure(lines, 'E1354: Cannot extend SomeVar')
31692
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
890
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
891 lines =<< trim END
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
892 vim9script
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
893 class Base
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
894 this.name: string
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
895 def ToString(): string
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
896 return this.name
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
897 enddef
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
898 endclass
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
899
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
900 class Child extends Base
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
901 this.age: number
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
902 def ToString(): string
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
903 return super.ToString() .. ': ' .. this.age
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
904 enddef
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
905 endclass
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
906
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
907 var o = Child.new('John', 42)
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
908 assert_equal('John: 42', o.ToString())
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
909 END
2f1af1b2f82d patch 9.0.1178: a child class cannot override functions from a base class
Bram Moolenaar <Bram@vim.org>
parents: 31653
diff changeset
910 v9.CheckScriptSuccess(lines)
31694
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
911
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
912 lines =<< trim END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
913 vim9script
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
914 class Child
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
915 this.age: number
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
916 def ToString(): number
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
917 return this.age
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
918 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
919 def ToString(): string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
920 return this.age
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
921 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
922 endclass
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
923 END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
924 v9.CheckScriptFailure(lines, 'E1355: Duplicate function: ToString')
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
925
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
926 lines =<< trim END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
927 vim9script
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
928 class Child
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
929 this.age: number
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
930 def ToString(): string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
931 return super .ToString() .. ': ' .. this.age
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
932 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
933 endclass
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
934 var o = Child.new(42)
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
935 echo o.ToString()
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
936 END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
937 v9.CheckScriptFailure(lines, 'E1356:')
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
938
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
939 lines =<< trim END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
940 vim9script
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
941 class Base
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
942 this.name: string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
943 def ToString(): string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
944 return this.name
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
945 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
946 endclass
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
947
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
948 var age = 42
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
949 def ToString(): string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
950 return super.ToString() .. ': ' .. age
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
951 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
952 echo ToString()
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
953 END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
954 v9.CheckScriptFailure(lines, 'E1357:')
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
955
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
956 lines =<< trim END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
957 vim9script
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
958 class Child
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
959 this.age: number
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
960 def ToString(): string
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
961 return super.ToString() .. ': ' .. this.age
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
962 enddef
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
963 endclass
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
964 var o = Child.new(42)
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
965 echo o.ToString()
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
966 END
2f61e308b997 patch 9.0.1179: not all errors around inheritance are tested
Bram Moolenaar <Bram@vim.org>
parents: 31692
diff changeset
967 v9.CheckScriptFailure(lines, 'E1358:')
31698
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
968
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
969 lines =<< trim END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
970 vim9script
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
971 class Base
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
972 this.name: string
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
973 static def ToString(): string
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
974 return 'Base class'
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
975 enddef
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
976 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
977
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
978 class Child extends Base
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
979 this.age: number
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
980 def ToString(): string
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
981 return Base.ToString() .. ': ' .. this.age
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
982 enddef
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
983 endclass
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
984
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
985 var o = Child.new('John', 42)
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
986 assert_equal('Base class: 42', o.ToString())
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
987 END
9fba3e8bbadc patch 9.0.1181: class inheritance and typing insufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 31694
diff changeset
988 v9.CheckScriptSuccess(lines)
31653
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
989 enddef
ec76f9d2319e patch 9.0.1159: extends argument for class not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 31649
diff changeset
990
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
991 def Test_class_import()
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
992 var lines =<< trim END
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
993 vim9script
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
994 export class Animal
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
995 this.kind: string
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
996 this.name: string
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
997 endclass
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
998 END
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
999 writefile(lines, 'Xanimal.vim', 'D')
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1000
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1001 lines =<< trim END
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1002 vim9script
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1003 import './Xanimal.vim' as animal
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1004
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1005 var a: animal.Animal
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1006 a = animal.Animal.new('fish', 'Eric')
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1007 assert_equal('fish', a.kind)
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1008 assert_equal('Eric', a.name)
31708
f6309f6742e5 patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
1009
f6309f6742e5 patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
1010 var b: animal.Animal = animal.Animal.new('cat', 'Garfield')
f6309f6742e5 patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
1011 assert_equal('cat', b.kind)
f6309f6742e5 patch 9.0.1186: imported class does not work when used twice in a line
Bram Moolenaar <Bram@vim.org>
parents: 31706
diff changeset
1012 assert_equal('Garfield', b.name)
31706
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1013 END
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1014 v9.CheckScriptSuccess(lines)
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1015 enddef
824fc05d9571 patch 9.0.1185: using class from imported script not tested
Bram Moolenaar <Bram@vim.org>
parents: 31704
diff changeset
1016
31443
9ae3720f9bd9 patch 9.0.1054: object member can't get type from initializer
Bram Moolenaar <Bram@vim.org>
parents: 31441
diff changeset
1017
31396
307f68a41b03 patch 9.0.1031: Vim9 class is not implemented yet
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker