Skip to content

Commit

Permalink
Try to git rid of isSuperOf and isSubOf
Browse files Browse the repository at this point in the history
  • Loading branch information
noti0na1 committed Jun 4, 2024
1 parent e87eb96 commit 94662bb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2536,35 +2536,35 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
*/
private def dropIfSuper(tp: Type, sub: Type): Type =

def isSuperOf(sub: Type): Boolean = sub match
case AndType(sub1, sub2) if isSuperOf(sub1) || isSuperOf(sub2) => true
case sub: TypeVar if sub.isInstantiated => isSuperOf(sub.instanceOpt)
case _ => isSubTypeWhenFrozen(sub, tp)
// def isSuperOf(sub: Type): Boolean = sub match
// case AndType(sub1, sub2) if isSuperOf(sub1) || isSuperOf(sub2) => true
// case sub: TypeVar if sub.isInstantiated => isSuperOf(sub.instanceOpt)
// case _ => isSubTypeWhenFrozen(sub, tp)

tp match
case tp @ AndType(tp1, tp2) =>
recombine(dropIfSuper(tp1, sub), dropIfSuper(tp2, sub), tp)
case tp: TypeVar if tp.isInstantiated =>
dropIfSuper(tp.instanceOpt, sub)
case _ =>
if isSuperOf(sub) then NoType else tp
if isSubTypeWhenFrozen(sub, tp) then NoType else tp
end dropIfSuper

/** If some (|-operand of) `tp` is a subtype of `sup` replace it with `NoType`. */
private def dropIfSub(tp: Type, sup: Type, canConstrain: Boolean): Type =

def isSubOf(sup: Type): Boolean = sup match
case OrType(sup1, sup2) if isSubOf(sup1) || isSubOf(sup2) => true
case sup: TypeVar if sup.isInstantiated => isSubOf(sup.instanceOpt)
case _ => isSubType(tp, sup, whenFrozen = !canConstrain)
// def isSubOf(sup: Type): Boolean = sup match
// case OrType(sup1, sup2) if isSubOf(sup1) || isSubOf(sup2) => true
// case sup: TypeVar if sup.isInstantiated => isSubOf(sup.instanceOpt)
// case _ => isSubType(tp, sup, whenFrozen = !canConstrain)

tp match
case tp @ OrType(tp1, tp2) =>
recombine(dropIfSub(tp1, sup, canConstrain), dropIfSub(tp2, sup, canConstrain), tp)
case tp: TypeVar if tp.isInstantiated =>
dropIfSub(tp.instanceOpt, sup, canConstrain)
case _ =>
if isSubOf(sup) then NoType else tp
if isSubType(tp, sup, whenFrozen = !canConstrain) then NoType else tp
end dropIfSub

/** There's a window of vulnerability between ElimByName and Erasure where some
Expand Down

0 comments on commit 94662bb

Please sign in to comment.