@@ -157,42 +157,47 @@ 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
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
183
+ }
181
184
}
182
185
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))
190
- }
186
+ getRightToLeftMapping map { rightToLeft =>
187
+ def checkParam (p2 : TypeParamRef ) =
188
+ rightToLeft(p2).match {
189
+ case null => false
190
+ case p1 : TypeParamRef =>
191
+ left.constraint.entry(p1).exists
192
+ && right.constraint.upper(p1).map(rightToLeft).forall(left.constraint.isLess(p1, _))
193
+ && isSubTypeWhenFrozen(left.constraint.nonParamBounds(p1), right.constraint.nonParamBounds(p2))
194
+ }
191
195
192
- def todos : Set [TypeParamRef ] =
193
- right.constraint.domainParams.toSet ++ pre.constraint.domainParams
196
+ def todos : Set [TypeParamRef ] =
197
+ right.constraint.domainParams.toSet ++ pre.constraint.domainParams
194
198
195
- todos.forall(checkParam)
199
+ todos.forall(checkParam)
200
+ } getOrElse false
196
201
}
197
202
198
203
(left, right, pre) match {
0 commit comments