Skip to content

Commit 55f9064

Browse files
committed
Get rid of isCappable
With the new info about approximations it's no longer needed.
1 parent f313ad7 commit 55f9064

File tree

1 file changed

+2
-18
lines changed

1 file changed

+2
-18
lines changed

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
354354
narrowGADTBounds(tp2, tp1, approx, isUpper = false)) &&
355355
GADTusage(tp2.symbol)
356356
}
357-
val tryLowerFirst = frozenConstraint || !isCappable(tp1)
358-
if (tryLowerFirst) isSubType(tp1, lo2, approx.addHigh) || compareGADT || fourthTry
359-
else compareGADT || fourthTry || isSubType(tp1, lo2, approx.addHigh)
357+
isSubType(tp1, lo2, approx.addHigh) || compareGADT || fourthTry
360358

361359
case _ =>
362360
val cls2 = tp2.symbol
@@ -389,7 +387,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
389387
val alwaysTrue =
390388
// The following condition is carefully formulated to catch all cases
391389
// where the subtype relation is true without needing to add a constraint
392-
// It's tricky because we might need to either appriximate tp2 by its
390+
// It's tricky because we might need to either approximate tp2 by its
393391
// lower bound or else widen tp1 and check that the result is a subtype of tp2.
394392
// So if the constraint is not yet frozen, we do the same comparison again
395393
// with a frozen constraint, which means that we get a chance to do the
@@ -1080,20 +1078,6 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
10801078
case _ => proto.isMatchedBy(tp)
10811079
}
10821080

1083-
/** Can type `tp` be constrained from above, either by adding a constraint to
1084-
* a typevar that it refers to, or by narrowing a GADT bound? In that case we have
1085-
* to be careful not to approximate with the lower bound of a type in `thirdTry`.
1086-
* Instead, we should first unroll `tp1` until we hit the type variable and bind the
1087-
* type variable with (the corresponding type in) `tp2` instead. Or, in the
1088-
* case of a GADT bounded typeref, we should narrow with `tp2` instead of its lower bound.
1089-
*/
1090-
private def isCappable(tp: Type): Boolean = tp match {
1091-
case tp: TypeParamRef => constraint contains tp
1092-
case tp: TypeProxy => isCappable(tp.underlying)
1093-
case tp: AndOrType => isCappable(tp.tp1) || isCappable(tp.tp2)
1094-
case _ => false
1095-
}
1096-
10971081
/** Narrow gadt.bounds for the type parameter referenced by `tr` to include
10981082
* `bound` as an upper or lower bound (which depends on `isUpper`).
10991083
* Test that the resulting bounds are still satisfiable.

0 commit comments

Comments
 (0)