@@ -6,20 +6,15 @@ class Foo(x)
6
6
//│ Foo: 'x -> (Foo with {x: 'x})
7
7
//│ = [Function: Foo1]
8
8
9
- :e
10
- :ge
11
- if 1 is 1 then 1
12
- //│ ╔══[ERROR] missing a default branch
13
- //│ ║ l.11: if 1 is 1 then 1
14
- //│ ╙── ^^^^^^^^^^^^^
15
- //│ res: error
16
- //│ Code generation encountered an error:
17
- //│ if expression has not been not desugared
9
+ if 1 is 1 then 1 else 0
10
+ //│ res: 0 | 1
11
+ //│ = 1
18
12
19
13
fun test(x) = if x is 1 then 0 else 1
20
14
//│ test: number -> (0 | 1)
21
15
//│ = [Function: test]
22
16
17
+ // It should report duplicated branches.
23
18
:w
24
19
fun testF(x) = if x is
25
20
Foo(a) then a
@@ -29,7 +24,6 @@ fun testF(x) = if x is
29
24
//│ testF: (Foo with {x: 'x}) -> 'x
30
25
//│ = [Function: testF]
31
26
32
-
33
27
class Bar(y, z)
34
28
//│ Defined class Bar
35
29
//│ Bar: ('y, 'z,) -> (Bar with {y: 'y, z: 'z})
@@ -47,19 +41,14 @@ class Pair(fst, snd)
47
41
//│ Pair: ('fst, 'snd,) -> (Pair with {fst: 'fst, snd: 'snd})
48
42
//│ = [Function: Pair1]
49
43
50
- :e
51
- :ge
52
- if x is
53
- Pair(0, 0) then "zeros"
54
- Pair(1, 1) then "ones"
55
- Pair(y, 1) then x
56
- _ then "nah"
57
- //│ ╔══[ERROR] identifier not found: x
58
- //│ ║ l.52: if x is
59
- //│ ╙── ^
60
- //│ res: "nah" | "ones" | "zeros"
61
- //│ Code generation encountered an error:
62
- //│ unresolved symbol x
44
+ fun f(x) =
45
+ if x is
46
+ Pair(0, 0) then "zeros"
47
+ Pair(1, 1) then "ones"
48
+ Pair(y, 1) then x
49
+ _ then "nah"
50
+ //│ f: (Pair & {fst: number, snd: number} & 'a | ~Pair) -> ("nah" | "ones" | "zeros" | 'a)
51
+ //│ = [Function: f]
63
52
64
53
class Z()
65
54
class O()
@@ -70,39 +59,58 @@ class O()
70
59
//│ O: () -> O
71
60
//│ = [Function: O1]
72
61
62
+ // This is not exhaustive.
73
63
:e
64
+ :ge
74
65
fun foo(x) = if x is
75
66
Pair(Z(), Z()) then "zeros"
76
67
Pair(O(), O()) then "ones"
77
68
//│ ╔══[ERROR] not exhaustive
78
- //│ ║ l.74 : fun foo(x) = if x is
69
+ //│ ║ l.65 : fun foo(x) = if x is
79
70
//│ ║ ^^^^
80
- //│ ║ l.75 : Pair(Z(), Z()) then "zeros"
71
+ //│ ║ l.66 : Pair(Z(), Z()) then "zeros"
81
72
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82
- //│ ║ l.76 : Pair(O(), O()) then "ones"
73
+ //│ ║ l.67 : Pair(O(), O()) then "ones"
83
74
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84
75
//│ foo: anything -> error
85
76
//│ Code generation encountered an error:
86
77
//│ if expression has not been not desugared
87
78
79
+ // Change `Pair` to a real pair.
80
+ :e
81
+ :ge
82
+ fun foo(x) = if x is
83
+ (Z(), Z()) then "zeros"
84
+ (O(), O()) then "ones"
85
+ //│ ╔══[ERROR] not exhaustive
86
+ //│ ║ l.82: fun foo(x) = if x is
87
+ //│ ║ ^^^^
88
+ //│ ║ l.83: (Z(), Z()) then "zeros"
89
+ //│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^
90
+ //│ ║ l.84: (O(), O()) then "ones"
91
+ //│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^
92
+ //│ foo: anything -> error
93
+ //│ Code generation encountered an error:
94
+ //│ if expression has not been not desugared
95
+
88
96
fun foo(x) = if x is
89
97
Pair(a, b) then if a is
90
98
Z() then if b is
91
99
Z() then "zeros"
92
100
O() then if b is
93
- O() then "zeros "
94
- //│ foo: (Pair & {fst: O | Z, snd: nothing}) -> " zeros"
95
- //│ = [Function: foo1 ]
101
+ O() then "ones "
102
+ //│ foo: (Pair & {fst: O | Z, snd: nothing}) -> ("ones" | " zeros")
103
+ //│ = [Function: foo2 ]
96
104
97
105
fun foo(x) = if x is
98
106
Pair(a, b) then if a is
99
107
Z() then if b is
100
108
Z() then "zeros"
101
109
else "???"
102
110
O() then if b is
103
- O() then "zeros "
104
- //│ foo: (Pair & {fst: O | Z, snd: O}) -> ("???" | "zeros")
105
- //│ = [Function: foo2 ]
111
+ O() then "ones "
112
+ //│ foo: (Pair & {fst: O | Z, snd: O}) -> ("???" | "ones" | " zeros")
113
+ //│ = [Function: foo3 ]
106
114
107
115
fun foo(x) = if x is
108
116
Pair(a, b) then if a is
@@ -113,13 +121,14 @@ fun foo(x) = if x is
113
121
O() then "zeros"
114
122
else "???"
115
123
//│ foo: (Pair & {fst: O | Z}) -> ("???" | "zeros")
116
- //│ = [Function: foo3 ]
124
+ //│ = [Function: foo4 ]
117
125
118
126
class S(pred)
119
127
//│ Defined class S
120
128
//│ S: 'pred -> (S with {pred: 'pred})
121
129
//│ = [Function: S1]
122
130
131
+ // TODO: Cannot check exhaustiveness of nested UCS yet.
123
132
fun foo(x) = if x is
124
133
Pair(a, b) then if a is
125
134
Z() then if b is
@@ -129,48 +138,49 @@ fun foo(x) = if x is
129
138
O() then "zeros"
130
139
else "???"
131
140
//│ foo: (Pair & {fst: O | Z, snd: (S with {pred: 'pred}) | ~S}) -> ("???" | "zeros" | 'pred)
132
- //│ = [Function: foo4 ]
141
+ //│ = [Function: foo5 ]
133
142
134
143
:re
135
144
foo(Pair(Z(), Z()))
136
145
//│ res: "???" | "zeros"
137
146
//│ Runtime error:
138
147
//│ Error: non-exhaustive case expression
139
148
149
+ :e
150
+ :ge
140
151
fun foo(x) = if x is
141
152
Pair(Z(), Z()) then "zeros"
142
153
Pair(O(), O()) then "ones"
143
154
Pair(y, O()) then x
144
155
//│ ╔══[ERROR] not exhaustive
145
- //│ ║ l.140 : fun foo(x) = if x is
156
+ //│ ║ l.151 : fun foo(x) = if x is
146
157
//│ ║ ^^^^
147
- //│ ║ l.141 : Pair(Z(), Z()) then "zeros"
158
+ //│ ║ l.152 : Pair(Z(), Z()) then "zeros"
148
159
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149
- //│ ║ l.142 : Pair(O(), O()) then "ones"
160
+ //│ ║ l.153 : Pair(O(), O()) then "ones"
150
161
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151
- //│ ║ l.143 : Pair(y, O()) then x
162
+ //│ ║ l.154 : Pair(y, O()) then x
152
163
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^
153
164
//│ foo: anything -> error
154
165
//│ Code generation encountered an error:
155
166
//│ if expression has not been not desugared
156
167
157
168
fun foo(x, y) = if x is Z() and y is O() then 0 else 1
158
169
//│ foo: (anything, anything,) -> (0 | 1)
159
- //│ = [Function: foo6 ]
170
+ //│ = [Function: foo7 ]
160
171
161
172
:pe
162
173
fun foo(x, y) = if x is
163
174
Z() and y is O() then 0 else 1
164
175
//│ ╔══[PARSE ERROR] Unexpected 'else' keyword here
165
- //│ ║ l.163 : Z() and y is O() then 0 else 1
176
+ //│ ║ l.174 : Z() and y is O() then 0 else 1
166
177
//│ ╙── ^^^^
167
178
//│ foo: (Z, O,) -> 0
168
- //│ = [Function: foo7 ]
179
+ //│ = [Function: foo8 ]
169
180
170
181
fun foo(x, y) =
171
182
if x is
172
183
Z() and y is O() then 0
173
184
else 1
174
185
//│ foo: (anything, anything,) -> (0 | 1)
175
- //│ = [Function: foo8]
176
-
186
+ //│ = [Function: foo9]
0 commit comments