Skip to content

Commit 7ebc282

Browse files
committed
Avoid isSubType recursions involving Nothing as upper bound
1 parent d4d957e commit 7ebc282

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
363363
narrowGADTBounds(tp2, tp1, approx, isUpper = false)) &&
364364
GADTusage(tp2.symbol)
365365
}
366-
isSubType(tp1, lo2, approx.addHigh) || compareGADT || fourthTry
366+
isSubApproxHi(tp1, lo2) || compareGADT || fourthTry
367367

368368
case _ =>
369369
val cls2 = tp2.symbol
@@ -750,7 +750,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
750750
* @param tyconLo The type constructor's lower approximation.
751751
*/
752752
def fallback(tyconLo: Type) =
753-
either(fourthTry, isSubType(tp1, tyconLo.applyIfParameterized(args2), approx.addHigh))
753+
either(fourthTry, isSubApproxHi(tp1, tyconLo.applyIfParameterized(args2)))
754754

755755
/** Let `tycon2bounds` be the bounds of the RHS type constructor `tycon2`.
756756
* Let `app2 = tp2` where the type constructor of `tp2` is replaced by
@@ -764,7 +764,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
764764
def compareLower(tycon2bounds: TypeBounds, tyconIsTypeRef: Boolean): Boolean =
765765
if (tycon2bounds.lo eq tycon2bounds.hi)
766766
if (tyconIsTypeRef) recur(tp1, tp2.superType)
767-
else isSubType(tp1, tycon2bounds.lo.applyIfParameterized(args2), approx.addHigh)
767+
else isSubApproxHi(tp1, tycon2bounds.lo.applyIfParameterized(args2))
768768
else
769769
fallback(tycon2bounds.lo)
770770

@@ -826,6 +826,9 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
826826
false
827827
} else isSubType(tp1, tp2, approx.addLow)
828828

829+
def isSubApproxHi(tp1: Type, tp2: Type): Boolean =
830+
(tp2 ne NothingType) && isSubType(tp1, tp2, approx.addHigh)
831+
829832
// begin recur
830833
if (tp2 eq NoType) false
831834
else if (tp1 eq tp2) true

0 commit comments

Comments
 (0)