@@ -222,10 +222,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
222
222
def dependentParams (tp : Type , isUpper : Boolean ): List [TypeParamRef ] = tp match {
223
223
case param : TypeParamRef if contains(param) =>
224
224
param :: (if (isUpper) upper(param) else lower(param))
225
- case tp : AndOrType =>
226
- val ps1 = dependentParams(tp.tp1, isUpper)
227
- val ps2 = dependentParams(tp.tp2, isUpper)
228
- if (isUpper == tp.isAnd) ps1.union(ps2) else ps1.intersect(ps2)
225
+ case tp : AndType => dependentParams(tp.tp1, isUpper).union (dependentParams(tp.tp2, isUpper))
226
+ case tp : OrType => dependentParams(tp.tp1, isUpper).intersect(dependentParams(tp.tp2, isUpper))
229
227
case _ =>
230
228
Nil
231
229
}
@@ -260,11 +258,18 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
260
258
case param : TypeParamRef if contains(param) =>
261
259
if (! paramBuf.contains(param)) paramBuf += param
262
260
NoType
263
- case tp : AndOrType if isUpper == tp.isAnd =>
261
+ case tp : AndType if isUpper =>
264
262
val tp1 = stripParams(tp.tp1, paramBuf, isUpper)
265
263
val tp2 = stripParams(tp.tp2, paramBuf, isUpper)
266
264
if (tp1.exists)
267
- if (tp2.exists) tp.derivedAndOrType(tp1, tp2)
265
+ if (tp2.exists) tp.derivedAndType(tp1, tp2)
266
+ else tp1
267
+ else tp2
268
+ case tp : OrType if ! isUpper =>
269
+ val tp1 = stripParams(tp.tp1, paramBuf, isUpper)
270
+ val tp2 = stripParams(tp.tp2, paramBuf, isUpper)
271
+ if (tp1.exists)
272
+ if (tp2.exists) tp.derivedOrType(tp1, tp2)
268
273
else tp1
269
274
else tp2
270
275
case _ =>
@@ -395,24 +400,32 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
395
400
def replaceParam (tp : Type , atPoly : TypeLambda , atIdx : Int ): Type = tp match {
396
401
case bounds @ TypeBounds (lo, hi) =>
397
402
398
- def recombine (andor : AndOrType , op : (Type , Boolean ) => Type , isUpper : Boolean ): Type = {
399
- val tp1 = op(andor.tp1, isUpper)
400
- val tp2 = op(andor.tp2, isUpper)
401
- if ((tp1 eq andor.tp1) && (tp2 eq andor.tp2)) andor
402
- else if (andor.isAnd) tp1 & tp2
403
+ def recombineAnd (and : AndType , op : (Type , Boolean ) => Type , isUpper : Boolean ): Type = {
404
+ val tp1 = op(and.tp1, isUpper)
405
+ val tp2 = op(and.tp2, isUpper)
406
+ if (tp1.eq(and.tp1) && tp2.eq(and.tp2)) and
407
+ else tp1 & tp2
408
+ }
409
+
410
+ def recombineOr (or : OrType , op : (Type , Boolean ) => Type , isUpper : Boolean ): Type = {
411
+ val tp1 = op(or.tp1, isUpper)
412
+ val tp2 = op(or.tp2, isUpper)
413
+ if (tp1.eq(or.tp1) && tp2.eq(or.tp2)) or
403
414
else tp1 | tp2
404
415
}
405
416
406
417
def normalize (tp : Type , isUpper : Boolean ): Type = tp match {
407
418
case p : TypeParamRef if p.binder == atPoly && p.paramNum == atIdx =>
408
419
if (isUpper) defn.AnyType else defn.NothingType
409
- case tp : AndOrType if isUpper == tp.isAnd => recombine(tp, normalize, isUpper)
420
+ case tp : AndType if isUpper => recombineAnd(tp, normalize, isUpper)
421
+ case tp : OrType if ! isUpper => recombineOr (tp, normalize, isUpper)
410
422
case _ => tp
411
423
}
412
424
413
425
def replaceIn (tp : Type , isUpper : Boolean ): Type = tp match {
414
426
case `param` => normalize(replacement, isUpper)
415
- case tp : AndOrType if isUpper == tp.isAnd => recombine(tp, replaceIn, isUpper)
427
+ case tp : AndType if isUpper => recombineAnd(tp, replaceIn, isUpper)
428
+ case tp : OrType if ! isUpper => recombineOr (tp, replaceIn, isUpper)
416
429
case _ => tp.substParam(param, replacement)
417
430
}
418
431
0 commit comments