Skip to content

Commit 17694b2

Browse files
committed
fix signature if unapply return Option[(T1, T2)]
1 parent 8639793 commit 17694b2

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
474474
val resTp = mt.resultType.select(nme.get).resultType.widen
475475
if (isUnapplySeq) scalaListType.appliedTo(resTp.argTypes.head) :: Nil
476476
else if (argLen == 0) Nil
477+
else if (isProductMatch(resTp, argLen))
478+
productSelectors(resTp).map(_.info.asSeenFrom(resTp, resTp.classSymbol).widen)
477479
else resTp :: Nil
478480
}
479481
}
@@ -711,14 +713,14 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
711713
showType(tp) + params(tp).map(_ => "_").mkString("(", ", ", ")")
712714
else if (decomposed) "_: " + showType(tp)
713715
else "_"
714-
case Prod(tp, fun, _, params, _) =>
716+
case Prod(tp, fun, sym, params, _) =>
715717
if (ctx.definitions.isTupleType(tp))
716718
"(" + params.map(doShow(_)).mkString(", ") + ")"
717719
else if (tp.isRef(scalaConsType.symbol))
718720
if (mergeList) params.map(doShow(_, mergeList)).mkString(", ")
719721
else params.map(doShow(_, true)).filter(_ != "Nil").mkString("List(", ", ", ")")
720722
else
721-
showType(tp) + params.map(doShow(_)).mkString("(", ", ", ")")
723+
showType(sym.owner.typeRef) + params.map(doShow(_)).mkString("(", ", ", ")")
722724
case Or(_) =>
723725
throw new Exception("incorrect flatten result " + s)
724726
}

tests/patmat/t10502.check

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
5: Pattern Match Exhaustivity: Option(None)
1+
5: Pattern Match Exhaustivity: Perhaps(None)
22
15: Pattern Match Exhaustivity: Nil
3+
31: Pattern Match Exhaustivity: Multi(None, _)
4+

tests/patmat/t10502.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,18 @@ object Perhaps {
1717
case Perhaps(None ) :: t => ()
1818
// case Nil => ()
1919
}
20+
21+
}
22+
23+
object Multi {
24+
def unapply(str: String): Some[(Option[Int], Int)] = ???
25+
26+
"hello" match {
27+
case Multi(Some(i), x) =>
28+
case Multi(None, x) =>
29+
}
30+
31+
"hello" match {
32+
case Multi(Some(i), x) =>
33+
}
2034
}

0 commit comments

Comments
 (0)