@@ -222,10 +222,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
222222 def dependentParams (tp : Type , isUpper : Boolean ): List [TypeParamRef ] = tp match {
223223 case param : TypeParamRef if contains(param) =>
224224 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))
229227 case _ =>
230228 Nil
231229 }
@@ -260,11 +258,18 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
260258 case param : TypeParamRef if contains(param) =>
261259 if (! paramBuf.contains(param)) paramBuf += param
262260 NoType
263- case tp : AndOrType if isUpper == tp.isAnd =>
261+ case tp : AndType if isUpper =>
264262 val tp1 = stripParams(tp.tp1, paramBuf, isUpper)
265263 val tp2 = stripParams(tp.tp2, paramBuf, isUpper)
266264 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)
268273 else tp1
269274 else tp2
270275 case _ =>
@@ -395,24 +400,32 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
395400 def replaceParam (tp : Type , atPoly : TypeLambda , atIdx : Int ): Type = tp match {
396401 case bounds @ TypeBounds (lo, hi) =>
397402
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
403414 else tp1 | tp2
404415 }
405416
406417 def normalize (tp : Type , isUpper : Boolean ): Type = tp match {
407418 case p : TypeParamRef if p.binder == atPoly && p.paramNum == atIdx =>
408419 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)
410422 case _ => tp
411423 }
412424
413425 def replaceIn (tp : Type , isUpper : Boolean ): Type = tp match {
414426 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)
416429 case _ => tp.substParam(param, replacement)
417430 }
418431
0 commit comments