Skip to content

Commit 301e4d0

Browse files
committed
Minor UCS PR polishing
1 parent 407fcad commit 301e4d0

15 files changed

+41
-41
lines changed

shared/src/main/scala/mlscript/Typer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ class Typer(var dbg: Boolean, var verbose: Bool, var explainErrors: Bool)
736736
iff.desugaredTerm = S(desugared)
737737
typeTerm(desugared)
738738
} catch {
739-
case e: DesugaringException => e.report(this)
739+
case e: DesugaringException => err(e.messages)
740740
}
741741
case New(S((nmedTy, trm)), TypingUnit(Nil)) =>
742742
typeTerm(App(Var(nmedTy.base.name).withLocOf(nmedTy), trm))

shared/src/main/scala/mlscript/ucs/Clause.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ object Clause {
6969
})
7070
}
7171
}
72-
}
72+
}

shared/src/main/scala/mlscript/ucs/Desugarer.scala

+3-4
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,10 @@ class Desugarer extends TypeDefs { self: Typer =>
533533
import Message.MessageContext
534534
parentOpt match {
535535
case S(IfThenElse(test, whenTrue, whenFalse)) =>
536-
if (whenFalse === t) {
537-
throw new DesugaringException(msg"Missing the otherwise case of test ${test.toString}", test.toLoc)
538-
} else {
536+
if (whenFalse === t)
537+
throw new DesugaringException(msg"The case when this is false is not handled: ${test.toString}", test.toLoc)
538+
else
539539
lastWords("`MissingCase` are not supposed to be the true branch of `IfThenElse`")
540-
}
541540
case S(Match(_, _, _)) =>
542541
lastWords("`MissingCase` are not supposed to be a case of `Match`")
543542
case S(Consequent(_)) | S(MissingCase) | N => die // unreachable

shared/src/main/scala/mlscript/ucs/DesugaringException.scala

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ package mlscript.ucs
33
import mlscript.{Diagnostic, Loc, Message, Typer}
44
import mlscript.utils.shorthands._
55

6-
class DesugaringException(messages: Ls[Message -> Opt[Loc]]) extends Throwable {
6+
class DesugaringException(val messages: Ls[Message -> Opt[Loc]]) extends Throwable {
77
def this(message: Message, location: Opt[Loc]) = this(message -> location :: Nil)
8-
def report(typer: Typer)(implicit raise: Diagnostic => Unit): typer.SimpleType = {
9-
typer.err(messages)
10-
}
118
}

shared/src/main/scala/mlscript/ucs/PartialTerm.scala

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,29 @@ class PartialTermError(term: PartialTerm, message: Str) extends Error(message)
1313
*
1414
* @param fragments fragment terms that used to build this `PartialTerm`.
1515
*/
16-
sealed abstract class PartialTerm(val fragments: Ls[Term]) {
16+
sealed abstract class PartialTerm {
17+
val fragments: Ls[Term]
1718
def addTerm(term: Term): PartialTerm.Total
1819
def addOp(op: Var): PartialTerm.Half
1920
def addTermOp(term: Term, op: Var): PartialTerm.Half =
2021
this.addTerm(term).addOp(op)
2122
}
2223

2324
object PartialTerm {
24-
final case object Empty extends PartialTerm(Nil) {
25+
final case object Empty extends PartialTerm {
26+
val fragments: Ls[Term] = Nil
2527
def addTerm(term: Term): Total = Total(term, term :: Nil)
2628
def addOp(op: Var): Half =
2729
throw new PartialTermError(this, s"expect a term but operator $op was given")
2830
}
2931

30-
final case class Total(val term: Term, override val fragments: Ls[Term]) extends PartialTerm(fragments) {
32+
final case class Total(term: Term, fragments: Ls[Term]) extends PartialTerm {
3133
def addTerm(term: Term): Total =
3234
throw new PartialTermError(this, s"expect an operator but term $term was given")
3335
def addOp(op: Var): Half = Half(term, op, op :: fragments)
3436
}
3537

36-
final case class Half(lhs: Term, op: Var, override val fragments: Ls[Term]) extends PartialTerm(fragments) {
38+
final case class Half(lhs: Term, op: Var, fragments: Ls[Term]) extends PartialTerm {
3739
def addTerm(rhs: Term): Total = {
3840
val (realRhs, extraExprOpt) = separatePattern(rhs)
3941
val leftmost = mkBinOp(lhs, op, realRhs)

shared/src/test/diff/mlscript/MatchBool.mls

+4-6
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ def absImpl lt x =
66
//│ absImpl: bool -> int -> int
77
//│ = [Function: absImpl]
88

9+
// * TODO support this
910
:e
1011
def abs x =
1112
let r = x < 0 in absImpl r x
1213
//│ ╔══[ERROR] Type mismatch in application:
13-
//│ ║ l.11: let r = x < 0 in absImpl r x
14+
//│ ║ l.12: let r = x < 0 in absImpl r x
1415
//│ ║ ^^^^^^^^^
1516
//│ ╟── operator application of type `bool` does not match type `false & ?a | true & ?b`
16-
//│ ║ l.11: let r = x < 0 in absImpl r x
17+
//│ ║ l.12: let r = x < 0 in absImpl r x
1718
//│ ║ ^^^^^
1819
//│ ╟── but it flows into reference with expected type `false & ?a | true & ?b`
19-
//│ ║ l.11: let r = x < 0 in absImpl r x
20+
//│ ║ l.12: let r = x < 0 in absImpl r x
2021
//│ ║ ^
2122
//│ ╟── Note: constraint arises from reference:
2223
//│ ║ l.3: case lt of
@@ -25,9 +26,6 @@ def abs x =
2526
//│ = [Function: abs]
2627

2728

28-
29-
30-
3129
def neg b = case b of
3230
{ true -> false
3331
| false -> true }

shared/src/test/diff/ucs/NestedBranches.mls

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fun mapPartition(f, xs) = if xs is
105105
Cons(x, xs) and mapPartition(f, xs) is (l, r) and f(x) is
106106
Left(v) then (Cons(v, l), r)
107107
Right(v) then (l, Cons(v, r))
108-
//│ ╔══[ERROR] Missing the otherwise case of test is (mapPartition (f, xs,),) (l, r,)
108+
//│ ╔══[ERROR] The case when this is false is not handled: is (mapPartition (f, xs,),) (l, r,)
109109
//│ ║ l.105: Cons(x, xs) and mapPartition(f, xs) is (l, r) and f(x) is
110110
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
111111
//│ mapPartition: (anything, anything,) -> error

shared/src/test/diff/ucs/NestedPattern.mls

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ fun crazy(v) =
3535
_ then "lol"
3636
//│ crazy: anything -> ("bruh!" | "lol")
3737

38+
39+
// * TODO(@chengluyu) fix these missing locations
40+
3841
:e
3942
fun f(x) =
4043
if x is
@@ -64,3 +67,4 @@ fun f(p) =
6467
//│ ╔══[ERROR] type identifier not found: Tuple#2
6568
//│ ╙──
6669
//│ f: (None | Some & {value: error}) -> (0 | error)
70+

shared/src/test/diff/ucs/SimpleUCS.mls

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ fun f(x, y) =
179179
> 0 then "gt"
180180
< 0 then "le"
181181
== 0 then "eq"
182-
//│ ╔══[ERROR] Missing the otherwise case of test == (y,) (0,)
182+
//│ ╔══[ERROR] The case when this is false is not handled: == (y,) (0,)
183183
//│ ║ l.178: Some(x) and y
184184
//│ ║ ^
185185
//│ ║ l.179: > 0 then "gt"

shared/src/test/diff/ucs/SplitAfterOp.mls

+9-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
fun f(x, b) =
66
if x ==
77
0 and b then 0
8-
//│ ╔══[ERROR] Missing the otherwise case of test b
8+
//│ ╔══[ERROR] The case when this is false is not handled: b
99
//│ ║ l.7: 0 and b then 0
1010
//│ ╙── ^
1111
//│ f: (anything, anything,) -> error
@@ -17,7 +17,7 @@ fun f(x, b) =
1717
if x == y +
1818
5 then 0
1919
7 then 0
20-
//│ ╔══[ERROR] Missing the otherwise case of test + (== (x,) (y,),) (7,)
20+
//│ ╔══[ERROR] The case when this is false is not handled: + (== (x,) (y,),) (7,)
2121
//│ ║ l.17: if x == y +
2222
//│ ║ ^^^^^^^^
2323
//│ ║ l.18: 5 then 0
@@ -33,7 +33,7 @@ if x == y +
3333
if x == y *
3434
5 then 0
3535
6 + 7 then 0
36-
//│ ╔══[ERROR] Missing the otherwise case of test * (== (x,) (y,),) (+ (6,) (7,),)
36+
//│ ╔══[ERROR] The case when this is false is not handled: * (== (x,) (y,),) (+ (6,) (7,),)
3737
//│ ║ l.33: if x == y *
3838
//│ ║ ^^^^^^^^
3939
//│ ║ l.34: 5 then 0
@@ -50,7 +50,7 @@ if x ==
5050
y +
5151
5 then 0
5252
7 then 0
53-
//│ ╔══[ERROR] Missing the otherwise case of test + (== (x,) (y,),) (7,)
53+
//│ ╔══[ERROR] The case when this is false is not handled: + (== (x,) (y,),) (7,)
5454
//│ ║ l.49: if x ==
5555
//│ ║ ^^^^
5656
//│ ║ l.50: y +
@@ -67,7 +67,7 @@ if x ==
6767
:ge
6868
if x ==
6969
1 and b then 0
70-
//│ ╔══[ERROR] Missing the otherwise case of test b
70+
//│ ╔══[ERROR] The case when this is false is not handled: b
7171
//│ ║ l.69: 1 and b then 0
7272
//│ ╙── ^
7373
//│ res: error
@@ -81,7 +81,7 @@ fun toEnglish(x) =
8181
if x ==
8282
true then "t"
8383
0 then "z"
84-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (0,)
84+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (0,)
8585
//│ ║ l.81: if x ==
8686
//│ ║ ^^^^
8787
//│ ║ l.82: true then "t"
@@ -98,7 +98,7 @@ fun toEnglish(x) =
9898
if x ==
9999
0 then "z"
100100
true then "t"
101-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (true,)
101+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (true,)
102102
//│ ║ l.98: if x ==
103103
//│ ║ ^^^^
104104
//│ ║ l.99: 0 then "z"
@@ -115,7 +115,7 @@ fun toEnglish(x) =
115115
if x ==
116116
1 then "o"
117117
0 then "z"
118-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (0,)
118+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (0,)
119119
//│ ║ l.115: if x ==
120120
//│ ║ ^^^^
121121
//│ ║ l.116: 1 then "o"
@@ -153,7 +153,7 @@ fun toEnglish(x) =
153153
//│ ╟── Note: 'if' expression started here:
154154
//│ ║ l.140: if x ==
155155
//│ ╙── ^^
156-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (undefined,)
156+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (undefined,)
157157
//│ ║ l.140: if x ==
158158
//│ ║ ^^^^
159159
//│ ║ l.141: else 1

shared/src/test/diff/ucs/SplitAnd.mls

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fun f(x) =
2626
B() then "B"
2727
x == 0 then "lol"
2828
else "bruh"
29-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (0,)
29+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (0,)
3030
//│ ║ l.23: if x == 0 and
3131
//│ ╙── ^^^^^^
3232
//│ f: anything -> error
@@ -40,7 +40,7 @@ fun f(x, y) =
4040
x == 0 and
4141
y == 0 then "bruh"
4242
else "lol"
43-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (0,)
43+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (0,)
4444
//│ ║ l.40: x == 0 and
4545
//│ ╙── ^^^^^^
4646
//│ f: (anything, anything,) -> error

shared/src/test/diff/ucs/SplitBeforeOp.mls

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:ge
55
if x
66
== 0 then 0
7-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (0,)
7+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (0,)
88
//│ ║ l.5: if x
99
//│ ║ ^
1010
//│ ║ l.6: == 0 then 0

shared/src/test/diff/ucs/SplitOps.mls

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ fun f(x) =
3333
is Left(v) then 0
3434
is Right(v) then 1
3535
<> undefined then 2
36-
//│ ╔══[ERROR] Missing the otherwise case of test <> (x,) (undefined,)
36+
//│ ╔══[ERROR] The case when this is false is not handled: <> (x,) (undefined,)
3737
//│ ║ l.32: if x
3838
//│ ║ ^
3939
//│ ║ l.33: is Left(v) then 0
@@ -97,7 +97,7 @@ fun f(a, b, c) =
9797
//│ Parsed: fun f = a, b, c, => {if a ‹· == (and (and (0,) (is (b,) (B (),),),) (is (c,) (C (),),)) then 0›};
9898
//│ Desugared: rec def f: a, b, c, => {if a ‹· == (and (and (0,) (is (b,) (B (),),),) (is (c,) (C (),),)) then 0›}
9999
//│ AST: Def(true, f, Lam(Tup(_: Var(a), _: Var(b), _: Var(c)), Blk(...)), true)
100-
//│ ╔══[ERROR] Missing the otherwise case of test and (is (b,) (B (),),) (is (c,) (C (),),)
100+
//│ ╔══[ERROR] The case when this is false is not handled: and (is (b,) (B (),),) (is (c,) (C (),),)
101101
//│ ║ l.95: == 0 and b is B() and c is C() then 0
102102
//│ ╙── ^^^^^^^^^^^^^^^^^^^^^
103103
//│ f: (anything, anything, anything,) -> error

shared/src/test/diff/ucs/TrivialIf.mls

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ map(None(), inc)
4343

4444
:e
4545
fun f(a, b) = if a and b then 0
46-
//│ ╔══[ERROR] Missing the otherwise case of test b
46+
//│ ╔══[ERROR] The case when this is false is not handled: b
4747
//│ ║ l.45: fun f(a, b) = if a and b then 0
4848
//│ ╙── ^
4949
//│ f: (anything, anything,) -> error
@@ -52,7 +52,7 @@ fun f(a, b) = if a and b then 0
5252
fun f(x, y) =
5353
if x == y + 5 then 0
5454
else if x == y + 7 then 0
55-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (+ (y,) (7,),)
55+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (+ (y,) (7,),)
5656
//│ ║ l.54: else if x == y + 7 then 0
5757
//│ ╙── ^^^^^^^^^^
5858
//│ f: (number, int,) -> (0 | error)

shared/src/test/diff/ucs/WeirdIf.mls

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fun f(x) = if x is else 0
3535
:ge
3636
if true
3737
then 0
38-
//│ ╔══[ERROR] Missing the otherwise case of test true
38+
//│ ╔══[ERROR] The case when this is false is not handled: true
3939
//│ ║ l.36: if true
4040
//│ ╙── ^^^^
4141
//│ res: error
@@ -63,7 +63,7 @@ fun f(x) =
6363
//│ ╟── Note: 'if' expression started here:
6464
//│ ║ l.50: if x ==
6565
//│ ╙── ^^
66-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (undefined,)
66+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (undefined,)
6767
//│ ║ l.50: if x ==
6868
//│ ║ ^^^^
6969
//│ ║ l.51: else "bruh"
@@ -86,7 +86,7 @@ fun boolToStr(x) =
8686
if x is
8787
true then "yah"
8888
false then "nah"
89-
//│ ╔══[ERROR] Missing the otherwise case of test == (x,) (false,)
89+
//│ ╔══[ERROR] The case when this is false is not handled: == (x,) (false,)
9090
//│ ║ l.86: if x is
9191
//│ ║ ^^^^
9292
//│ ║ l.87: true then "yah"

0 commit comments

Comments
 (0)