Skip to content

Commit 91c9afc

Browse files
committed
Document widenScrutinee & check original scrutinee first
1 parent 27ae379 commit 91c9afc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+12-4
Original file line numberDiff line numberDiff line change
@@ -1007,10 +1007,18 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
10071007
case tp1: MatchType =>
10081008
def compareMatch = tp2 match {
10091009
case tp2: MatchType =>
1010-
val scrutinee1 = tp1.scrutinee match
1011-
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
1012-
case tp => tp.widenSkolem
1013-
isSameType(scrutinee1, tp2.scrutinee) &&
1010+
// we allow a small number of scrutinee types to be widened:
1011+
// * skolems, which may appear from type avoidance, but are widened in the inferred result type
1012+
// * inline proxies, which is inlining's solution to the same problem
1013+
def widenScrutinee(scrutinee1: Type) = scrutinee1 match
1014+
case tp: TermRef if tp.symbol.is(InlineProxy) => tp.info
1015+
case tp => tp.widenSkolem
1016+
def checkScrutinee(scrutinee1: Type): Boolean =
1017+
isSameType(scrutinee1, tp2.scrutinee) || {
1018+
val widenScrutinee1 = widenScrutinee(scrutinee1)
1019+
(widenScrutinee1 ne scrutinee1) && checkScrutinee(widenScrutinee1)
1020+
}
1021+
checkScrutinee(tp1.scrutinee) &&
10141022
tp1.cases.corresponds(tp2.cases)(isSubType)
10151023
case _ => false
10161024
}

0 commit comments

Comments
 (0)