-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtests.t
271 lines (228 loc) · 6.74 KB
/
tests.t
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
Boolean equality
$ stlc-variant-unification elab <<< "true = false"
#bool-eq -true false : Bool
Integer equality
$ stlc-variant-unification elab <<< "1 = 2"
#int-eq -1 2 : Bool
Integer Addition
$ stlc-variant-unification elab <<< "1 + 2"
#int-add -1 2 : Int
Add two function
$ stlc-variant-unification elab <<< "fun x => x + 2"
fun (x : Int) => #int-add -x 2 : Int -> Int
Function application
$ stlc-variant-unification elab <<< "fun x f => f x * x"
fun (x : Int) => fun (f : Int -> Int) => #int-mul -(f x) x :
Int -> (Int -> Int) -> Int
Function application
$ stlc-variant-unification elab <<< "let f x := x; f 3"
let f : Int -> Int := fun (x : Int) => x;
f 3 : Int
Explicit parameter type
$ stlc-variant-unification elab <<< "let f (x : Int) := x; f 3"
let f : Int -> Int := fun (x : Int) => x;
f 3 : Int
Explicit return type
$ stlc-variant-unification elab <<< "let f (x : Int) : Int := x; f 3"
let f : Int -> Int := fun (x : Int) => x;
f 3 : Int
Placeholder types
$ stlc-variant-unification elab <<< "let f (x : _) : _ := x; f 3"
let f : Int -> Int := fun (x : Int) => x;
f 3 : Int
Placeholder return type
$ stlc-unification elab <<< "let f : Int -> _ := fun x y => x; f 3 true"
let f : Int -> Bool -> Int := fun (x : Int) => fun (y : Bool) => x;
f 3 true : Int
If expressions
$ stlc-variant-unification elab <<< "fun x y => if x = 0 then y else 3"
fun (x : Int) => fun (y : Int) => if #int-eq -x 0 then y else 3 :
Int -> Int -> Int
Variant literal
$ stlc-variant-unification elab <<< "[some := 1]"
[some := 1] : [some : Int] : [some : Int]
Match expression
$ stlc-variant-unification elab <<EOF
> fun x =>
> match x with
> | [a := x] => x + 1
> | [b := x] => x
> end
> EOF
fun (x : [a : Int | b : Int]) =>
match x with | [a := x] => #int-add -x 1 | [b := x] => x end
: [a : Int | b : Int] -> Int
Absurd match
$ stlc-variant-unification elab <<< "(fun x => match x with end) : _ -> Int "
fun (x : [|]) => match x with end : [|] -> Int
Variant constraint and variant type
$ stlc-variant-unification elab <<EOF
> let choose b y n :=
> if b then [yes := y] else [no := n];
>
> let result : [yes : Int | no : Bool | maybe : Int] :=
> choose true 3 false;
>
> result
> EOF
let choose : Bool -> Int -> Bool -> [maybe : Int | no : Bool | yes : Int] :=
fun (b : Bool) => fun (y : Int) => fun (n : Bool) =>
if b then
([yes := y] : [maybe : Int | no : Bool | yes : Int])
else
[no := n] : [maybe : Int | no : Bool | yes : Int];
let result : [maybe : Int | no : Bool | yes : Int] := choose true 3 false;
result : [maybe : Int | no : Bool | yes : Int]
Lexer Errors
------------
Unexpected character
$ stlc-variant-unification elab <<< "1 % 2"
<input>:1:2: unexpected character
[1]
Unclosed block comment
$ stlc-variant-unification elab <<< "/- hellooo"
<input>:2:0: unclosed block comment
[1]
Parse Errors
------------
Unclosed parenthesis
$ stlc-variant-unification elab <<< "1 + (3 "
<input>:2:0: syntax error
[1]
Elaboration Errors
------------------
Unbound variable
$ stlc-variant-unification elab <<< "let x := 1; y"
<input>:1:12: unbound name `y`
[1]
Mismatched definition type
$ stlc-variant-unification elab <<< "let x : Bool := 1; x"
<input>:1:16: mismatched types:
expected: Bool
found: Int
[1]
Mismatched argument
$ stlc-variant-unification elab <<< "let f x := x + 1; f f"
<input>:1:20: mismatched types:
expected: Int
found: Int -> Int
[1]
Mismatched argument
$ stlc-variant-unification elab <<< "let f (x : Bool) := x; f 1"
<input>:1:25: mismatched types:
expected: Bool
found: Int
[1]
Mismatched variant constraint and variant type
$ stlc-variant-unification elab <<EOF
> let choose b y n :=
> if b then [yes := y] else [no := n];
>
> let result : [yes : Int | no : Int] :=
> choose true 3 false;
>
> result
> EOF
<input>:5:2: mismatched types:
expected: [no : Int | yes : Int]
found: ?{4 ~ [no : Bool | yes : Int]}
[1]
Mismatched variant constraint and smaller variant type
$ stlc-variant-unification elab <<EOF
> let choose b y n :=
> if b then [yes := y] else [no := n];
>
> let result : [yes : Int] :=
> choose true 3 false;
>
> result
> EOF
<input>:5:2: mismatched types:
expected: [yes : Int]
found: ?{4 ~ [no : Bool | yes : Int]}
[1]
Mismatched variant constraint and non-variant type
$ stlc-variant-unification elab <<EOF
> let choose b y n :=
> if b then [yes := y] else [no := n];
>
> let result : Bool :=
> choose true 3 false;
>
> result
> EOF
<input>:5:2: mismatched types:
expected: Bool
found: ?{4 ~ [no : Bool | yes : Int]}
[1]
Infinite type
$ stlc-variant-unification elab <<< "fun f => f f"
<input>:1:11: infinite type
[1]
Unexpected parameter
$ stlc-unification elab <<< "(fun x y => x) : Int -> Int"
<input>:1:7: unexpected parameter
[1]
Ambiguous parameter type
$ stlc-variant-unification elab <<< "fun x => x"
<input>:1:4: ambiguous function parameter type
[1]
Ambiguous return type
$ stlc-variant-unification elab <<< "fun f x => f x"
<input>:1:6: ambiguous function parameter type
<input>:1:11: ambiguous function return type
[1]
Ambiguous placeholder
$ stlc-variant-unification elab <<< "fun (x : _) => x"
<input>:1:9: unsolved placeholder
[1]
Mismatched if expression branches
$ stlc-variant-unification elab <<< "fun x => if x then true else 3"
<input>:1:29: mismatched types:
expected: Bool
found: Int
[1]
Duplicate labels
$ stlc-variant-unification elab <<< "[some := 1] : [some : Int | some : Int]"
<input>:1:28: duplicate label `some`
[1]
Unexpected variant
$ stlc-variant-unification elab <<< "[some := 1] : [thing : Int]"
<input>:1:1: unexpected variant `some` in type `[thing : Int]`
[1]
Redundant variant pattern
$ stlc-variant-unification elab <<EOF
> fun (x : [some : Int]) =>
> match x with
> | [some := x] => x + 1
> | [some := x] => x
> end
> EOF
<input>:4:5: redundant variant pattern `some`
[1]
Unexpected variant pattern
$ stlc-variant-unification elab <<EOF
> fun (x : [some : Int]) =>
> match x with
> | [a := x] => x + 1
> end
> EOF
<input>:3:5: unexpected variant pattern `a`
[1]
Missing variant patterns
$ stlc-variant-unification elab <<EOF
> fun (x : [a : Int | b : Bool]) =>
> match x with end
> EOF
<input>:2:8: non-exhaustive match, missing `a`, `b`
[1]
Mismatched equality
$ stlc-variant-unification elab <<< "1 = false"
<input>:1:0: mismatched types:
expected: Int
found: Bool
[1]
Unsupported equality
$ stlc-variant-unification elab <<< "let f (x : Bool) := x; f = f"
<input>:1:23: unsupported type: Bool -> Bool
[1]