@@ -384,22 +384,15 @@ object Types {
384384
385385 /** The base classes of this type as determined by ClassDenotation
386386 * in linearization order, with the class itself as first element.
387- * For AndTypes/OrTypes, the merge/intersection of the operands' baseclasses .
388- * Inherited by all type proxies. `Nil` for all other types.
387+ * Inherited by all type proxies. Overridden for And and Or types .
388+ * `Nil` for all other types.
389389 */
390- final def baseClasses (implicit ctx : Context ): List [ClassSymbol ] = track(" baseClasses" ) {
390+ def baseClasses (implicit ctx : Context ): List [ClassSymbol ] = track(" baseClasses" ) {
391391 this match {
392392 case tp : TypeProxy =>
393393 tp.underlying.baseClasses
394394 case tp : ClassInfo =>
395395 tp.cls.baseClasses
396- case AndType (tp1, tp2) =>
397- (new BaseDataBuilder )
398- .addAll(tp1.baseClasses)
399- .addAll(tp2.baseClasses)
400- .baseClasses
401- case OrType (tp1, tp2) =>
402- tp1.baseClasses intersect tp2.baseClasses
403396 case _ => Nil
404397 }
405398 }
@@ -2307,6 +2300,37 @@ object Types {
23072300 def tp2 : Type
23082301 def isAnd : Boolean
23092302 def derivedAndOrType (tp1 : Type , tp2 : Type )(implicit ctx : Context ): Type // needed?
2303+
2304+ private [this ] var myBaseClassesPeriod : Period = Nowhere
2305+ private [this ] var myBaseClasses : List [ClassSymbol ] = _
2306+
2307+ /** Base classes of And are the merge of the operand base classes
2308+ * For OrTypes, it's the intersection.
2309+ */
2310+ override final def baseClasses (implicit ctx : Context ) = {
2311+ if (myBaseClassesPeriod != ctx.period) {
2312+ val bcs1 = tp1.baseClasses
2313+ val bcs1set = BaseClassSet (bcs1)
2314+ def recur (bcs2 : List [ClassSymbol ]): List [ClassSymbol ] = bcs2 match {
2315+ case bc2 :: bcs2rest =>
2316+ if (isAnd)
2317+ if (bcs1set contains bc2)
2318+ if (bc2.is(Trait )) recur(bcs2rest)
2319+ else bcs1 // common class, therefore rest is the same in both sequences
2320+ else bc2 :: recur(bcs2rest)
2321+ else
2322+ if (bcs1set contains bc2)
2323+ if (bc2.is(Trait )) bc2 :: recur(bcs2rest)
2324+ else bcs2rest
2325+ else recur(bcs2rest)
2326+ case nil =>
2327+ if (isAnd) bcs1 else bcs2
2328+ }
2329+ myBaseClasses = recur(tp2.baseClasses)
2330+ myBaseClassesPeriod = ctx.period
2331+ }
2332+ myBaseClasses
2333+ }
23102334 }
23112335
23122336 abstract case class AndType (tp1 : Type , tp2 : Type ) extends CachedGroundType with AndOrType {
0 commit comments