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
-- Tests for displaying Kailua types.
--8<-- display-named
--# type X = string
local x = 42 --: X
--@^ Error: Cannot assign `42` into `X`
--@^^ Note: The other type originates here
--! error
--8<-- display-named-nil-1
--# type X = string
local x = 42 --: X?
--@^ Error: Cannot assign `42` into `X?`
--@^^ Note: The other type originates here
--! error
--8<-- display-named-nil-2
--# type X = string?
local x = 42 --: X?
--@^ Error: Cannot assign `42` into `X`
--@^^ Note: The other type originates here
--! error
--8<-- display-named-no-nil-1
--# type X = string
local x = 42 --: X!
--@^ Error: Cannot assign `42` into `X!`
--@^^ Note: The other type originates here
--! error
--8<-- display-named-no-nil-2
--# type X = string!
local x = 42 --: X!
--@^ Error: Cannot assign `42` into `X`
--@^^ Note: The other type originates here
--! error
--8<-- display-named-no-nil-3
--# type X = string?
local x = 42 --: X!
--@^ Error: Cannot assign `42` into `X!`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-maximally-disjoint
local a = true --: true | 42 | 'foobar' | thread | userdata | (function()) | {string}
local b = a --: nil
--@^ Error: Cannot assign `(true|thread|userdata|42|"foobar"|{string}|function() --> ())` into `nil`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-nil
--# type X = string?
--# type Y = integer
local x = 42.5 --: X | Y
--@^ Error: Cannot assign `number` into `(string|Y)?`
--@^^ Note: The other type originates here
-- XXX this is not entirely intentional but stems from the current implementation strategy:
-- ? or ! are separate from unions, so unions cannot have hints including them.
-- in the future unions can be made more flexible and have any kind of hints.
--! error
--8<-- display-union-same
--# type X = string
local x = 42 --: X | X | X
--@^ Error: Cannot assign `42` into `X`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-duplicates
--# type X = string
--# type Y = string
local x = 42 --: X | Y
--@^ Error: Cannot assign `42` into `string`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-disjoint-1
--# type X = 1|2|3
--# type Y = 4|5
local x = 42 --: X | Y
--@^ Error: Cannot assign `42` into `(X|Y)`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-disjoint-2
--# type X = integer|string
--# type Y = string|boolean
local x = 42.5 --: X | Y
--@^ Error: Cannot assign `number` into `(X|Y)`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-disjoint-unnamed
--# type X = string|boolean
local x = 42.5 --: integer | X
--@^ Error: Cannot assign `number` into `(integer|X)`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-overlap
--# type X = 1|2|3
--# type Y = 3|4|5
local x = 42 --: X | Y
--@^ Error: Cannot assign `42` into `(X|Y)`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-includes-named-1
--# type X = 1|2|3
--# type Y = 1|2
local x = 42 --: X | Y
--@^ Error: Cannot assign `42` into `(X|Y)`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-includes-named-2
--# type X = 1|2|3
--# type Y = integer
local x = 42.5 --: X | Y
--@^ Error: Cannot assign `number` into `Y`
--@^^ Note: The other type originates here
--! error
--8<-- display-union-includes-unnamed
--# type X = 1|2|3
local x = 42 --: 3 | X
--@^ Error: Cannot assign `42` into `X`
--@^^ Note: The other type originates here
--! error
--8<-- display-rec-recursive-1
local x =
x. = x
x. = x
x. = x
local a = x --: integer
--@^ Error: Cannot assign `{x: <variable x>, y: <variable x>, z: <variable x>, ...}` into `integer`
--@^^ Note: The other type originates here
--! error
--8<-- display-rec-recursive-2
local x =
x. = x
x. = x
x. = x
local y =
y. = y
y. = x
-- this error is actually quite wrong, because it occurred in midst of recursive rvar relation...
x = y
--@^ Error: Cannot assign `{x: <variable y>, y: <variable x>, ...}` into `{x: <variable y>, y: <variable x>, z: <variable x>, ...}`
--@^^ Note: The other type originates here
--! error
--8<-- display-rec-recursive-3
local u =
u. = u
u. = 0
--@^ Error: Cannot assign `0` into `{u: <...>, ...}`
--@^^ Note: The other type originates here
--! error
--8<-- display-same-names
local x =
local y = x. --@< Error: Missing key "x" in `{a: X, b: X#1, c: Y, d: X#2, e: Y#1, ...}`
--! error