1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
-- Class tests for the Kailua type checker.
--8<-- assume-class-local
local Hello
--# assume class Hello
local x --: Hello
--! ok
--8<-- assume-class-global
--# assume global class Hello
local x --: Hello
--! ok
--8<-- assume-class-unknown-class-system
--# assume global class(unknown) Hello --@< Error: `unknown` class system hasn't been defined
--! error
--8<-- assume-class-undefined-class-system
-- the `gideros` class system actually exists but should be explicitly defined
--# assume global class(gideros) Hello --@< Error: `gideros` class system hasn't been defined
--! error
--8<-- assume-class-duplicate-name
--# type Hello = integer
--# assume global class Hello --@< Error: A type `Hello` is already defined
--@^^ Note: The type was originally defined here
local x --: Hello
local y = x + 3 --: integer
--! error
--8<-- class-field-static
--# assume global class Hello
Hello. = 42
local x = Hello. + 5 --: integer
--! ok
--8<-- class-field-instance
--# assume global class Hello
--v method()
--v method()
--! ok
--8<-- assume-field-class-local
local Hello
--# assume class Hello
--# assume Hello.f: function(Hello) --> string
--# assume static Hello.g: function() --> string
--# assume h: Hello
local x = h: --: string
local y = h. --: string
--! ok
--8<-- assume-field-class-local-export
--# assume global `require`: [require] function(string) --> any
local Hello = require --@< Warning: A new name for the previously named class is ignored
--# assume h: Hello
local x = h: --: string
local y = h. --: string
--& x
local Hello
--# assume class Hello --@< Note: The class was previously named here
--# assume Hello.f: function(Hello) --> string
--# assume static Hello.g: function() --> string
return Hello
--! ok
--8<-- assume-field-class-global
--# assume global class Hello
--# assume Hello.f: function(Hello) --> string
--# assume static Hello.g: function() --> string
--# assume h: Hello
local x = h: --: string
local y = h. --: string
--! ok
--8<-- assume-field-class-global-export
--# assume global `require`: [require] function(string) --> any
require
--# assume h: Hello
local x = h: --: string
local y = h. --: string
--& x
--# assume global class Hello
--# assume Hello.f: function(Hello) --> string
--# assume static Hello.g: function() --> string
--! ok
--8<-- assume-field-class-nested
--# assume global class Hello
--# assume Hello.f.x: function(Hello) --> string
--@^ Error: Cannot apply `--# assume` directive to the inside of fields in the class prototype of `Hello`
--# assume static Hello.g.y: function() --> string
--@^ Error: Cannot apply `--# assume` directive to the inside of fields in the class prototype of `Hello`
--# assume h: Hello
local x = h: --: string --@< Error: Cannot index `Hello` with `"f"`
local y = h. --: string --@< Error: Cannot index `Hello` with `"g"`
--! error
--8<-- assume-field-class-fields
--# assume global class Hello
--# assume Hello.x: integer
--# assume static Hello.y: string
--v method(n: integer)
--# assume h: Hello
h:
local x = h. --: integer
local y = h. --: string
local xx = Hello. --: integer --@< Error: Cannot index `<initializing> <prototype for Hello>` with `"x"`
local yy = Hello. --: string
--! error
--8<-- assume-field-class-method
--# assume global class Hello
--# assume Hello.f: method() --> string
--# assume Hello.g: method(s: string, base: integer?) --> number
--# assume h: Hello
local x = h: --: string
local y = h. --: number
--! ok
--8<-- assume-field-class-method-nested
--# assume global class Hello
--# assume Hello.f.g: method() --> string
--@^ Error: Cannot apply `--# assume` directive to the inside of fields in the class prototype of `Hello`
--# assume h: Hello
local x = h: --: string --@< Error: Cannot index `Hello` with `"f"`
local y = h. --: string --@< Error: Cannot index `Hello` with `"g"`
--! error
--8<-- class-implicit-module
--# assume global class Hello
--# assume Hello.n: integer
--v method()
--v method()
--! ok
--8<-- class-implicit-module-partial-init
--# assume global class Hello
--# assume Hello.n: integer
--v method()
--v method()
--# assume h: Hello
h:
--! ok
--8<-- class-nil-field-1
--# assume global class Hello
--# assume static Hello.p: integer
--# assume static Hello.q: integer!
--# assume static Hello.r: integer?
local u = Hello. --: string --@< Error: Cannot assign `integer` into `string`
--@^ Note: The other type originates here
local v = Hello. --: string --@< Error: Cannot assign `integer!` into `string`
--@^ Note: The other type originates here
local w = Hello. --: string --@< Error: Cannot assign `integer?` into `string`
--@^ Note: The other type originates here
--! error
--8<-- class-nil-field
--# assume global class Hello
--# assume Hello.p: integer
--# assume Hello.q: integer!
--# assume Hello.r: integer?
--v method()
--! error
--8<-- make-class-no-class-system
--# assume `class`: [make_class] function() --> table
--@^ Error: The type attribute `make_class` requires exactly 1 value(s)
--# assume `class`: [make_class()] function() --> table
--@^ Error: The type attribute `make_class` requires exactly 1 value(s)
--! error
--8<-- make-class-unknown-class-system
-- the `gideros` class system actually exists but should be explicitly defined
--# assume `class`: [make_class(gideros)] function() --> table
--@^ Error: `gideros` class system hasn't been defined
--! error