Skip to content

Commit 36281b3

Browse files
authored
Merge pull request #5425 from dotty-staging/fix-5422
Fix #5422: prefer type tp1 in Typ(tp1) - Prod(tp2, ...)
2 parents 2d23cba + b222e9f commit 36281b3

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ trait SpaceLogic {
243243
else a
244244
case (Typ(tp1, _), Prod(tp2, fun, sym, ss, true)) =>
245245
// rationale: every instance of `tp1` is covered by `tp2(_)`
246-
if (isSubType(tp1, tp2)) minus(Prod(tp2, fun, sym, signature(fun, sym, ss.length).map(Typ(_, false)), true), b)
246+
if (isSubType(tp1, tp2)) minus(Prod(tp1, fun, sym, signature(fun, sym, ss.length).map(Typ(_, false)), true), b)
247247
else if (canDecompose(tp1)) tryDecompose1(tp1)
248248
else a
249249
case (_, Or(ss)) =>

tests/patmat/i5422.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.language.higherKinds
2+
3+
object Test {
4+
5+
trait X
6+
case object Y extends X
7+
8+
sealed trait Foo[F[_], O] {
9+
def bar: Foo[F, O] = this match {
10+
case Qux(fa, f) => qux(fa) {
11+
case Left(Y) => ???
12+
case x => ???
13+
}
14+
}
15+
}
16+
17+
case class Qux[F[_], A, O](fa: F[A], f: Either[X, A] => Int) extends Foo[F, O]
18+
19+
def qux[F[_], A, O](fa: F[A])(f: Either[X, A] => Int): Foo[F, O] =
20+
Qux(fa, f)
21+
}

0 commit comments

Comments
 (0)