Skip to content

Commit ed8c657

Browse files
committed
Always assume two TypeTest[S, T].unapply are the same
if they are equivalent in types.
1 parent 2666bae commit ed8c657

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
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
@@ -521,7 +521,9 @@ class SpaceEngine(using Context) extends SpaceLogic {
521521
}
522522

523523
def isSameUnapply(tp1: TermRef, tp2: TermRef): Boolean =
524-
tp1.prefix.isStable && tp2.prefix.isStable && tp1 =:= tp2
524+
// always assume two TypeTest[S, T].unapply are the same if they are equal in types
525+
(tp1.prefix.isStable && tp2.prefix.isStable || tp1.symbol == defn.TypeTest_unapply)
526+
&& tp1 =:= tp2
525527

526528
/** Parameter types of the case class type `tp`. Adapted from `unapplyPlan` in patternMatcher */
527529
def signature(unapp: TermRef, scrutineeTp: Type, argLen: Int): List[Type] = {
@@ -590,7 +592,7 @@ class SpaceEngine(using Context) extends SpaceLogic {
590592
/** Whether the extractor covers the given type */
591593
def covers(unapp: TermRef, scrutineeTp: Type): Boolean =
592594
SpaceEngine.isIrrefutable(unapp) || unapp.symbol == defn.TypeTest_unapply && {
593-
val AppliedType(_, _ :: tp :: Nil) = unapp.prefix.widen
595+
val AppliedType(_, _ :: tp :: Nil) = unapp.prefix.widen.dealias
594596
scrutineeTp <:< tp
595597
}
596598

tests/patmat/i12020.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
19: Pattern Match Exhaustivity: _: TypeDef

0 commit comments

Comments
 (0)