Skip to content

Commit

Permalink
Document widenScrutinee & check original scrutinee first
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jun 28, 2023
1 parent 27ae379 commit 91c9afc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1007,10 +1007,18 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
case tp1: MatchType =>
def compareMatch = tp2 match {
case tp2: MatchType =>
val scrutinee1 = tp1.scrutinee match
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
case tp => tp.widenSkolem
isSameType(scrutinee1, tp2.scrutinee) &&
// we allow a small number of scrutinee types to be widened:
// * skolems, which may appear from type avoidance, but are widened in the inferred result type
// * inline proxies, which is inlining's solution to the same problem
def widenScrutinee(scrutinee1: Type) = scrutinee1 match
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
case tp => tp.widenSkolem
def checkScrutinee(scrutinee1: Type): Boolean =
isSameType(scrutinee1, tp2.scrutinee) || {
val widenScrutinee1 = widenScrutinee(scrutinee1)
(widenScrutinee1 ne scrutinee1) && checkScrutinee(widenScrutinee1)
}
checkScrutinee(tp1.scrutinee) &&
tp1.cases.corresponds(tp2.cases)(isSubType)
case _ => false
}
Expand Down

0 comments on commit 91c9afc

Please sign in to comment.