Skip to content

Commit

Permalink
fix type signature to pass null check
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Aug 17, 2022
1 parent 0133b2e commit 1dd8a48
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,42 +157,43 @@ final class ProperGadtConstraint private(
*/
def subsumes(left: GadtConstraint, right: GadtConstraint, pre: GadtConstraint)(using Context): Boolean =
def checkSubsumes(left: ProperGadtConstraint, right: ProperGadtConstraint, pre: ProperGadtConstraint): Boolean = {
def rightToLeft: TypeParamRef => TypeParamRef = {
def getRightToLeftMapping: Option[TypeParamRef => TypeParamRef] = {
val preParams = pre.constraint.domainParams.toSet
val mapping = {
var res: SimpleIdentityMap[TypeParamRef, TypeParamRef] = SimpleIdentityMap.empty
var hasNull: Boolean = false

right.constraint.domainParams.foreach { p2 =>
left.tvarOf(right.externalize(p2)) match {
case null =>
hasNull = true
case tv: TypeVar =>
res = res.updated(p2, tv.origin)
}
}

res
if hasNull then None else Some(res)
}

def func(p2: TypeParamRef) =
if pre.constraint.domainParams contains p2 then p2
else mapping(p2)

func
}

def checkParam(p2: TypeParamRef) =
rightToLeft(p2).match {
case null => false
case p1: TypeParamRef =>
left.constraint.entry(p1).exists
&& right.constraint.upper(p1).map(rightToLeft).forall(left.constraint.isLess(p1, _))
&& isSubTypeWhenFrozen(left.constraint.nonParamBounds(p1), right.constraint.nonParamBounds(p2))
mapping map { mapping =>
def func(p2: TypeParamRef) =
if pre.constraint.domainParams contains p2 then p2
else mapping(p2).nn
func
}
}

def todos: Set[TypeParamRef] =
right.constraint.domainParams.toSet ++ pre.constraint.domainParams

todos.forall(checkParam)
getRightToLeftMapping map { rightToLeft =>
def checkParam(p2: TypeParamRef) =
val p1 = rightToLeft(p2)
left.constraint.entry(p1).exists
&& right.constraint.upper(p1).map(rightToLeft).forall(left.constraint.isLess(p1, _))
&& isSubTypeWhenFrozen(left.constraint.nonParamBounds(p1), right.constraint.nonParamBounds(p2))
def todos: Set[TypeParamRef] =
right.constraint.domainParams.toSet ++ pre.constraint.domainParams

todos.forall(checkParam)
} getOrElse false
}

(left, right, pre) match {
Expand Down

0 comments on commit 1dd8a48

Please sign in to comment.