@@ -157,42 +157,43 @@ final class ProperGadtConstraint private(
157157 */
158158 def subsumes (left : GadtConstraint , right : GadtConstraint , pre : GadtConstraint )(using Context ): Boolean =
159159 def checkSubsumes (left : ProperGadtConstraint , right : ProperGadtConstraint , pre : ProperGadtConstraint ): Boolean = {
160- def rightToLeft : TypeParamRef => TypeParamRef = {
160+ def getRightToLeftMapping : Option [ TypeParamRef => TypeParamRef ] = {
161161 val preParams = pre.constraint.domainParams.toSet
162162 val mapping = {
163163 var res : SimpleIdentityMap [TypeParamRef , TypeParamRef ] = SimpleIdentityMap .empty
164+ var hasNull : Boolean = false
164165
165166 right.constraint.domainParams.foreach { p2 =>
166167 left.tvarOf(right.externalize(p2)) match {
167168 case null =>
169+ hasNull = true
168170 case tv : TypeVar =>
169171 res = res.updated(p2, tv.origin)
170172 }
171173 }
172174
173- res
175+ if hasNull then None else Some ( res)
174176 }
175177
176- def func (p2 : TypeParamRef ) =
177- if pre.constraint.domainParams contains p2 then p2
178- else mapping(p2)
179-
180- func
181- }
182-
183- def checkParam (p2 : TypeParamRef ) =
184- rightToLeft(p2).match {
185- case null => false
186- case p1 : TypeParamRef =>
187- left.constraint.entry(p1).exists
188- && right.constraint.upper(p1).map(rightToLeft).forall(left.constraint.isLess(p1, _))
189- && isSubTypeWhenFrozen(left.constraint.nonParamBounds(p1), right.constraint.nonParamBounds(p2))
178+ mapping map { mapping =>
179+ def func (p2 : TypeParamRef ) =
180+ if pre.constraint.domainParams contains p2 then p2
181+ else mapping(p2).nn
182+ func
190183 }
184+ }
191185
192- def todos : Set [TypeParamRef ] =
193- right.constraint.domainParams.toSet ++ pre.constraint.domainParams
194-
195- todos.forall(checkParam)
186+ getRightToLeftMapping map { rightToLeft =>
187+ def checkParam (p2 : TypeParamRef ) =
188+ val p1 = rightToLeft(p2)
189+ left.constraint.entry(p1).exists
190+ && right.constraint.upper(p1).map(rightToLeft).forall(left.constraint.isLess(p1, _))
191+ && isSubTypeWhenFrozen(left.constraint.nonParamBounds(p1), right.constraint.nonParamBounds(p2))
192+ def todos : Set [TypeParamRef ] =
193+ right.constraint.domainParams.toSet ++ pre.constraint.domainParams
194+
195+ todos.forall(checkParam)
196+ } getOrElse false
196197 }
197198
198199 (left, right, pre) match {
@@ -830,7 +831,7 @@ final class ProperGadtConstraint private(
830831
831832 override def isEquivalent (p : PathType , q : PathType ) = false
832833
833- override def approximation (sym : Symbol , fromBelow : Boolean )(using Context ): Type = unsupported(" EmptyGadtConstraint.approximation" )
834+ override def approximation (sym : Symbol , fromBelow : Boolean , maxLevel : Int )(using Context ): Type = unsupported(" EmptyGadtConstraint.approximation" )
834835
835836 override def symbols : List [Symbol ] = Nil
836837
0 commit comments