Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reachability by retaining spaces of Prod params #14118

Merged
merged 1 commit into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,20 @@ trait SpaceLogic {
if (isSubType(tp2, tp1)) b
else if (canDecompose(tp1)) tryDecompose1(tp1)
else if (isSubType(tp1, tp2)) a // problematic corner case: inheriting a case class
else intersectUnrelatedAtomicTypes(tp1, tp2)
else intersectUnrelatedAtomicTypes(tp1, tp2) match
case Typ(tp, _) => Prod(tp, fun, ss)
case sp => sp
case (Prod(tp1, fun, ss), Typ(tp2, _)) =>
if (isSubType(tp1, tp2)) a
else if (canDecompose(tp2)) tryDecompose2(tp2)
else if (isSubType(tp2, tp1)) a // problematic corner case: inheriting a case class
else intersectUnrelatedAtomicTypes(tp1, tp2)
else intersectUnrelatedAtomicTypes(tp1, tp2) match
case Typ(tp, _) => Prod(tp, fun, ss)
case sp => sp
case (Prod(tp1, fun1, ss1), Prod(tp2, fun2, ss2)) =>
if (!isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2)
if (!isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2) match
case Typ(tp, _) => Prod(tp, fun1, ss1)
case sp => sp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: We could experiment by introducing a space called Unknown(tp: Type) for this case later.

Edited: Sorry, I meant the case above (the 1st case).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case is only for Empty, when the two types are provably disjoint, so I'm not sure what we'd want to preserve the type for. But I'm not against the idea.

else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty)) Empty
else Prod(tp1, fun1, ss1.zip(ss2).map((intersect _).tupled))
}
Expand Down
7 changes: 7 additions & 0 deletions tests/patmat/i14102.min.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trait Foo[-X]
case class Bar(n: Int) extends Foo[Nothing]

def test[X](foo: Foo[X]) = foo match
case Bar(1) =>
case Bar(_) =>
case _ =>
8 changes: 8 additions & 0 deletions tests/patmat/i14102.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
trait T[-X]
case class CC[-X](x: List[T[X]]) extends T[Nothing]
case class Id[-X](x: String) extends T[X]

def f[X](tree: T[X]) = tree match
case CC(Id("hi") :: Nil) => ???
case CC(refs) => ???
case _ => ???