Skip to content

Commit 63d18ee

Browse files
committed
Fix the absurd warning
1 parent 5120f0d commit 63d18ee

File tree

2 files changed

+14
-29
lines changed

2 files changed

+14
-29
lines changed

hkmc2/shared/src/main/scala/hkmc2/semantics/ucs/Desugarer.scala

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,10 @@ class Desugarer(val elaborator: Elaborator)
9090
def ++(fallback: Split): Split =
9191
if fallback == Split.End then
9292
split
93-
else if split.isFull then
94-
raise:
95-
ErrorReport:
96-
msg"The following branches are unreachable." -> fallback.toLoc ::
97-
msg"Because the previous split is full." -> split.toLoc :: Nil
98-
split
9993
else (split match
10094
case Split.Cons(head, tail) => Split.Cons(head, tail ++ fallback)
10195
case Split.Let(name, term, tail) => Split.Let(name, term, tail ++ fallback)
102-
case Split.Else(_) /* impossible */ | Split.End => fallback)
96+
case Split.Else(_) | Split.End => fallback)
10397

10498
private val subScrutineeMap = HashMap.empty[BlockLocalSymbol, ScrutineeData]
10599
private val fieldScrutineeMap = HashMap.empty[BlockLocalSymbol, ScrutineeData]
@@ -466,9 +460,7 @@ class Desugarer(val elaborator: Elaborator)
466460
if pat.patternParams.size > 0 then
467461
error(
468462
msg"Pattern `${pat.nme}` expects ${"pattern argument".pluralize(pat.patternParams.size, true)}" ->
469-
pat.patternParams.foldLeft[Opt[Loc]](N):
470-
case (N, param) => param.sym.toLoc
471-
case (S(loc), param) => S(loc ++ param.sym.toLoc),
463+
Loc(pat.patternParams.iterator.map(_.sym)),
472464
msg"But no arguments were given" -> ctor.toLoc)
473465
fallback
474466
else
@@ -515,12 +507,8 @@ class Desugarer(val elaborator: Elaborator)
515507
if pat.patternParams.size != patArgs.size then
516508
error(
517509
msg"Pattern `${pat.nme}` expects ${"pattern argument".pluralize(pat.patternParams.size, true)}" ->
518-
pat.patternParams.foldLeft[Opt[Loc]](N):
519-
case (N, param) => param.sym.toLoc
520-
case (S(loc), param) => S(loc ++ param.sym.toLoc),
521-
msg"But ${"pattern argument".pluralize(patArgs.size, true)} were given" -> args.foldLeft[Opt[Loc]](N):
522-
case (N, arg) => arg.toLoc
523-
case (S(loc), arg) => S(loc ++ arg.toLoc))
510+
Loc(pat.patternParams.iterator.map(_.sym)),
511+
msg"But ${"pattern argument".pluralize(patArgs.size, true)} were given" -> Loc(args))
524512
fallback
525513
else
526514
Branch(ref, Pattern.Synonym(pat, patArgs.zip(args)), sequel(ctx)) ~: fallback

hkmc2/shared/src/test/mlscript/ucs/patterns/ConjunctionPattern.mls

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,23 @@ if A is
1111
else 3
1212
//│ = 2
1313

14-
:e
1514
if A is
1615
A & A & B then 0
1716
B & A & B then 1
1817
A & A & A then 2
1918
else 3
2019
//│ = 2
21-
//│ FAILURE: Unexpected lack of type error
2220

2321
:sjs
24-
:todo
25-
if A is
26-
A & y then y
22+
fun foo(v) =
23+
if v is
24+
A & B then 1
2725
else 0
28-
//│ ╔══[ERROR] The following branches are unreachable.
29-
//│ ║ l.27: else 0
30-
//│ ║ ^
31-
//│ ╟── Because the previous split is full.
32-
//│ ║ l.26: A & y then y
33-
//│ ╙── ^
3426
//│ JS (unsanitized):
35-
//│ let scrut2, y; scrut2 = A1; if (scrut2 instanceof A1.class) { y = scrut2; y } else { 0 }
36-
//│ = A
27+
//│ let foo; foo = function foo(v) { if (v instanceof A1.class) { return 0 } else { return 0 } };
28+
29+
foo(A)
30+
//│ = 0
31+
32+
foo(B)
33+
//│ = 0

0 commit comments

Comments
 (0)