diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index ff4a00a4d68f..3aa0528cf982 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -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 }