Skip to content

Commit 5ecb8c0

Browse files
committed
Generalize logic by using either
1 parent 655851c commit 5ecb8c0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,20 +905,21 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
905905
|| widenAbstractOKFor(tp2)
906906
|| tp1.widen.underlyingClassRef(refinementOK = true).exists)
907907
then
908-
if isSubType(base, tp2, if tp1.isRef(cls2) then approx else approx.addLow) then
909-
recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp1) }
910-
else if tp1.widenDealias.isInstanceOf[AndType] || base.isInstanceOf[OrType] then
908+
def checkBase =
909+
isSubType(base, tp2, if tp1.isRef(cls2) then approx else approx.addLow)
910+
&& recordGadtUsageIf { MatchType.thatReducesUsingGadt(tp1) }
911+
if tp1.widenDealias.isInstanceOf[AndType] || base.isInstanceOf[OrType] then
911912
// If tp1 is a intersection, it could be that one of the original
912913
// branches of the AndType tp1 conforms to tp2, but its base type does
913914
// not, or else that its base type for cls2 does not exist, in which case
914915
// it would not show up in `base`. In either case, we need to also fall back
915-
// to fourthTry. Test case is i18226a.scala.
916+
// to fourthTry. Test cases are i18266.scala and i18226a.scala.
916917
// If base is a disjunction, this might have come from a tp1 type that
917918
// expands to a match type. In this case, we should try to reduce the type
918919
// and compare the redux. This is done in fourthTry
919-
fourthTry
920+
either(checkBase, fourthTry)
920921
else
921-
false
922+
checkBase
922923
else fourthTry
923924

924925
def fourthTry: Boolean = tp1 match {

0 commit comments

Comments
 (0)