Skip to content

Commit 2e395f4

Browse files
author
Florent Ferrari
committed
more tests
1 parent 5120f0d commit 2e395f4

File tree

1 file changed

+70
-4
lines changed

1 file changed

+70
-4
lines changed
Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
:js
2+
import "../../../mlscript-compile/Stack.mls"
3+
4+
open Stack
25

36

47
object A
58
object B
9+
data class C(a)
610

711
if A is
812
A & A & B then 0
@@ -11,26 +15,88 @@ if A is
1115
else 3
1216
//│ = 2
1317

14-
:e
1518
if A is
1619
A & A & B then 0
1720
B & A & B then 1
1821
A & A & A then 2
1922
else 3
2023
//│ = 2
21-
//│ FAILURE: Unexpected lack of type error
2224

2325
:sjs
2426
:todo
2527
if A is
2628
A & y then y
2729
else 0
2830
//│ ╔══[ERROR] The following branches are unreachable.
29-
//│ ║ l.27: else 0
31+
//│ ║ l.29: else 0
3032
//│ ║ ^
3133
//│ ╟── Because the previous split is full.
32-
//│ ║ l.26: A & y then y
34+
//│ ║ l.28: A & y then y
3335
//│ ╙── ^
3436
//│ JS (unsanitized):
3537
//│ let scrut2, y; scrut2 = A1; if (scrut2 instanceof A1.class) { y = scrut2; y } else { 0 }
3638
//│ = A
39+
40+
fun range(i, j) =
41+
if i > j then Nil
42+
else i :: range(i+1, j)
43+
44+
fun suffixes(l) = if l is
45+
Nil then Cons(Nil, Nil)
46+
l & (_ :: tl) then l :: suffixes(tl)
47+
48+
suffixes(range(0, 5))
49+
//│ = Cons(Cons(0, Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil)))))), Cons(Cons(1, Cons(2, Cons(3, Cons(4, Cons(5, Nil))))), Cons(Cons(2, Cons(3, Cons(4, Cons(5, Nil)))), Cons(Cons(3, Cons(4, Cons(5, Nil))), Cons(Cons(4, Cons(5, Nil)), Cons(Cons(5, Nil), Cons(Nil, Nil)))))))
50+
51+
suffixes(range(0, -1))
52+
//│ = Cons(Nil, Nil)
53+
54+
suffixes(range(0, 0))
55+
//│ = Cons(Cons(0, Nil), Cons(Nil, Nil))
56+
57+
if 5 is a & b & c then a+b+c
58+
//│ = 15
59+
60+
:e
61+
fun foo(x) = if x is
62+
{a:_ & a} & C and
63+
a is 1 then 10
64+
a is 2 then 20
65+
else 30
66+
else 40
67+
//│ ╔══[ERROR] The following branches are unreachable.
68+
//│ ║ l.66: else 40
69+
//│ ║ ^^
70+
//│ ╟── Because the previous split is full.
71+
//│ ║ l.62: {a:_ & a} & C and
72+
//│ ║ ^^^^^
73+
//│ ║ l.63: a is 1 then 10
74+
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^
75+
//│ ║ l.64: a is 2 then 20
76+
//│ ║ ^^^^^^^^^^^^^^^^^^^^^^
77+
//│ ║ l.65: else 30
78+
//│ ║ ^^^^^^^^^^^^^^^
79+
//│ ║ l.66: else 40
80+
//│ ╙── ^^^^^^^^^^^
81+
82+
foo(C(1))
83+
//│ = 40
84+
85+
foo(4)
86+
//│ = 40
87+
88+
:ucs desugared
89+
:ucs normalized
90+
C(1) is C & {:a}
91+
//│ FAILURE: Unexpected type error
92+
//│ FAILURE LOCATION: ++ (Desugarer.scala:95)
93+
//│ ╔══[ERROR] The following branches are unreachable.
94+
//│ ╙── Because the previous split is full.
95+
//│ Normalized:
96+
//│ > if
97+
//│ > let $scrut = member:C#666(1)
98+
//│ > $scrut is C and
99+
//│ > let a = $scrut#1
100+
//│ > else true
101+
//│ > else false
102+
//│ = true

0 commit comments

Comments
 (0)