Skip to content

Commit fa00ce5

Browse files
committed
fix: Union type error
1 parent f3dd2a3 commit fa00ce5

File tree

2 files changed

+333
-46
lines changed

2 files changed

+333
-46
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,22 +1018,27 @@ class Typer(var dbg: Boolean, var verbose: Bool, var explainErrors: Bool, val ne
10181018
typeTerms(tup :: Nil, false, Nil)
10191019
case Tup(fs) =>
10201020
TupleType(fs.mapConserve { case e @ (n, f @ Fld(flags, t)) =>
1021-
n match {
1022-
case S(v) if ctx.inPattern =>
1023-
(n, Fld(flags,
1024-
// Asc(v, t.toTypeRaise).withLoc(v.toLoc.fold(t.toLoc)(_ ++ t.toLoc |> some))))
1025-
Asc(v, Union(t.toTypeRaise, Literal(UnitLit(true)))).withLoc(v.toLoc.fold(t.toLoc)(_ ++ t.toLoc |>some))))
1026-
case N if flags.opt =>
1027-
t match {
1028-
case v: Var if ctx.inPattern =>
1029-
(n, Fld(flags,
1030-
Asc(v, Union(TypeVar(R(""), N), Literal(UnitLit(true)))).withLoc(v.toLoc.fold(t.toLoc)(_ ++ t.toLoc |> some))))
1031-
case _ =>
1032-
// if ctx.inPattern // TODO[optional-fields]
1033-
err("Error here", f.toLoc) // TODO[optional-fields]
1034-
e
1021+
{
1022+
val res = n match {
1023+
case S(v) if ctx.inPattern =>
1024+
(n, Fld(flags,
1025+
Asc(v, t.toTypeRaise).withLoc(v.toLoc.fold(t.toLoc)(_ ++ t.toLoc |> some))))
1026+
case N if flags.opt => {
1027+
val res = t match {
1028+
case v: Var if ctx.inPattern =>
1029+
(n, Fld(flags,
1030+
Asc(v, Union(TypeVar(R(""), N), Literal(UnitLit(true)))).withLoc(v.toLoc.fold(t.toLoc)(_ ++ t.toLoc |> some))))
1031+
case _ =>
1032+
// if ctx.inPattern // TODO[optional-fields]
1033+
err("Error here", f.toLoc) // TODO[optional-fields]
1034+
e
1035+
}
1036+
res
10351037
}
1036-
case _ => e
1038+
case _ => e
1039+
}
1040+
println(s"dbg [Typer.scala]: $res opt: ${flags.opt}")
1041+
res
10371042
}
10381043
}.map { case (n, Fld(FldFlags(mut, spec, opt, getter), t)) =>
10391044
if (getter)

0 commit comments

Comments
 (0)