Skip to content

Commit 0f6df73

Browse files
authored
Merge pull request #14118 from dwijnand/contrareach
Fix reachability by retaining spaces of Prod params
2 parents b3ab102 + a648468 commit 0f6df73

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,20 @@ trait SpaceLogic {
212212
if (isSubType(tp2, tp1)) b
213213
else if (canDecompose(tp1)) tryDecompose1(tp1)
214214
else if (isSubType(tp1, tp2)) a // problematic corner case: inheriting a case class
215-
else intersectUnrelatedAtomicTypes(tp1, tp2)
215+
else intersectUnrelatedAtomicTypes(tp1, tp2) match
216+
case Typ(tp, _) => Prod(tp, fun, ss)
217+
case sp => sp
216218
case (Prod(tp1, fun, ss), Typ(tp2, _)) =>
217219
if (isSubType(tp1, tp2)) a
218220
else if (canDecompose(tp2)) tryDecompose2(tp2)
219221
else if (isSubType(tp2, tp1)) a // problematic corner case: inheriting a case class
220-
else intersectUnrelatedAtomicTypes(tp1, tp2)
222+
else intersectUnrelatedAtomicTypes(tp1, tp2) match
223+
case Typ(tp, _) => Prod(tp, fun, ss)
224+
case sp => sp
221225
case (Prod(tp1, fun1, ss1), Prod(tp2, fun2, ss2)) =>
222-
if (!isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2)
226+
if (!isSameUnapply(fun1, fun2)) intersectUnrelatedAtomicTypes(tp1, tp2) match
227+
case Typ(tp, _) => Prod(tp, fun1, ss1)
228+
case sp => sp
223229
else if (ss1.zip(ss2).exists(p => simplify(intersect(p._1, p._2)) == Empty)) Empty
224230
else Prod(tp1, fun1, ss1.zip(ss2).map((intersect _).tupled))
225231
}

tests/patmat/i14102.min.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait Foo[-X]
2+
case class Bar(n: Int) extends Foo[Nothing]
3+
4+
def test[X](foo: Foo[X]) = foo match
5+
case Bar(1) =>
6+
case Bar(_) =>
7+
case _ =>

tests/patmat/i14102.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait T[-X]
2+
case class CC[-X](x: List[T[X]]) extends T[Nothing]
3+
case class Id[-X](x: String) extends T[X]
4+
5+
def f[X](tree: T[X]) = tree match
6+
case CC(Id("hi") :: Nil) => ???
7+
case CC(refs) => ???
8+
case _ => ???

0 commit comments

Comments
 (0)