@@ -157,42 +157,43 @@ final class ProperGadtConstraint private(
157
157
*/
158
158
def subsumes (left : GadtConstraint , right : GadtConstraint , pre : GadtConstraint )(using Context ): Boolean =
159
159
def checkSubsumes (left : ProperGadtConstraint , right : ProperGadtConstraint , pre : ProperGadtConstraint ): Boolean = {
160
- def rightToLeft : TypeParamRef => TypeParamRef = {
160
+ def getRightToLeftMapping : Option [ TypeParamRef => TypeParamRef ] = {
161
161
val preParams = pre.constraint.domainParams.toSet
162
162
val mapping = {
163
163
var res : SimpleIdentityMap [TypeParamRef , TypeParamRef ] = SimpleIdentityMap .empty
164
+ var hasNull : Boolean = false
164
165
165
166
right.constraint.domainParams.foreach { p2 =>
166
167
left.tvarOf(right.externalize(p2)) match {
167
168
case null =>
169
+ hasNull = true
168
170
case tv : TypeVar =>
169
171
res = res.updated(p2, tv.origin)
170
172
}
171
173
}
172
174
173
- res
175
+ if hasNull then None else Some ( res)
174
176
}
175
177
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
190
183
}
184
+ }
191
185
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
196
197
}
197
198
198
199
(left, right, pre) match {
0 commit comments