Skip to content

Commit c304723

Browse files
committed
Review test cases
1 parent a8b1052 commit c304723

File tree

5 files changed

+213
-284
lines changed

5 files changed

+213
-284
lines changed

shared/src/test/diff/nu/Humiliation.mls

+53-43
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ class Foo(x)
66
//│ Foo: 'x -> (Foo with {x: 'x})
77
//│ = [Function: Foo1]
88

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
1812

1913
fun test(x) = if x is 1 then 0 else 1
2014
//│ test: number -> (0 | 1)
2115
//│ = [Function: test]
2216

17+
// It should report duplicated branches.
2318
:w
2419
fun testF(x) = if x is
2520
Foo(a) then a
@@ -29,7 +24,6 @@ fun testF(x) = if x is
2924
//│ testF: (Foo with {x: 'x}) -> 'x
3025
//│ = [Function: testF]
3126

32-
3327
class Bar(y, z)
3428
//│ Defined class Bar
3529
//│ Bar: ('y, 'z,) -> (Bar with {y: 'y, z: 'z})
@@ -47,19 +41,14 @@ class Pair(fst, snd)
4741
//│ Pair: ('fst, 'snd,) -> (Pair with {fst: 'fst, snd: 'snd})
4842
//│ = [Function: Pair1]
4943

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]
6352

6453
class Z()
6554
class O()
@@ -70,39 +59,58 @@ class O()
7059
//│ O: () -> O
7160
//│ = [Function: O1]
7261

62+
// This is not exhaustive.
7363
:e
64+
:ge
7465
fun foo(x) = if x is
7566
Pair(Z(), Z()) then "zeros"
7667
Pair(O(), O()) then "ones"
7768
//│ ╔══[ERROR] not exhaustive
78-
//│ ║ l.74: fun foo(x) = if x is
69+
//│ ║ l.65: fun foo(x) = if x is
7970
//│ ║ ^^^^
80-
//│ ║ l.75: Pair(Z(), Z()) then "zeros"
71+
//│ ║ l.66: Pair(Z(), Z()) then "zeros"
8172
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82-
//│ ║ l.76: Pair(O(), O()) then "ones"
73+
//│ ║ l.67: Pair(O(), O()) then "ones"
8374
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8475
//│ foo: anything -> error
8576
//│ Code generation encountered an error:
8677
//│ if expression has not been not desugared
8778

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+
8896
fun foo(x) = if x is
8997
Pair(a, b) then if a is
9098
Z() then if b is
9199
Z() then "zeros"
92100
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]
96104

97105
fun foo(x) = if x is
98106
Pair(a, b) then if a is
99107
Z() then if b is
100108
Z() then "zeros"
101109
else "???"
102110
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]
106114

107115
fun foo(x) = if x is
108116
Pair(a, b) then if a is
@@ -113,13 +121,14 @@ fun foo(x) = if x is
113121
O() then "zeros"
114122
else "???"
115123
//│ foo: (Pair & {fst: O | Z}) -> ("???" | "zeros")
116-
//│ = [Function: foo3]
124+
//│ = [Function: foo4]
117125

118126
class S(pred)
119127
//│ Defined class S
120128
//│ S: 'pred -> (S with {pred: 'pred})
121129
//│ = [Function: S1]
122130

131+
// TODO: Cannot check exhaustiveness of nested UCS yet.
123132
fun foo(x) = if x is
124133
Pair(a, b) then if a is
125134
Z() then if b is
@@ -129,48 +138,49 @@ fun foo(x) = if x is
129138
O() then "zeros"
130139
else "???"
131140
//│ foo: (Pair & {fst: O | Z, snd: (S with {pred: 'pred}) | ~S}) -> ("???" | "zeros" | 'pred)
132-
//│ = [Function: foo4]
141+
//│ = [Function: foo5]
133142

134143
:re
135144
foo(Pair(Z(), Z()))
136145
//│ res: "???" | "zeros"
137146
//│ Runtime error:
138147
//│ Error: non-exhaustive case expression
139148

149+
:e
150+
:ge
140151
fun foo(x) = if x is
141152
Pair(Z(), Z()) then "zeros"
142153
Pair(O(), O()) then "ones"
143154
Pair(y, O()) then x
144155
//│ ╔══[ERROR] not exhaustive
145-
//│ ║ l.140: fun foo(x) = if x is
156+
//│ ║ l.151: fun foo(x) = if x is
146157
//│ ║ ^^^^
147-
//│ ║ l.141: Pair(Z(), Z()) then "zeros"
158+
//│ ║ l.152: Pair(Z(), Z()) then "zeros"
148159
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
149-
//│ ║ l.142: Pair(O(), O()) then "ones"
160+
//│ ║ l.153: Pair(O(), O()) then "ones"
150161
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151-
//│ ║ l.143: Pair(y, O()) then x
162+
//│ ║ l.154: Pair(y, O()) then x
152163
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^
153164
//│ foo: anything -> error
154165
//│ Code generation encountered an error:
155166
//│ if expression has not been not desugared
156167

157168
fun foo(x, y) = if x is Z() and y is O() then 0 else 1
158169
//│ foo: (anything, anything,) -> (0 | 1)
159-
//│ = [Function: foo6]
170+
//│ = [Function: foo7]
160171

161172
:pe
162173
fun foo(x, y) = if x is
163174
Z() and y is O() then 0 else 1
164175
//│ ╔══[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
166177
//│ ╙── ^^^^
167178
//│ foo: (Z, O,) -> 0
168-
//│ = [Function: foo7]
179+
//│ = [Function: foo8]
169180

170181
fun foo(x, y) =
171182
if x is
172183
Z() and y is O() then 0
173184
else 1
174185
//│ foo: (anything, anything,) -> (0 | 1)
175-
//│ = [Function: foo8]
176-
186+
//│ = [Function: foo9]

0 commit comments

Comments
 (0)