@@ -584,46 +584,40 @@ object SpaceEngine {
584
584
585
585
/** Decompose a type into subspaces -- assume the type can be decomposed */
586
586
def decompose (tp : Type )(using Context ): List [Typ ] = trace(i " decompose( $tp) " , debug, showSpaces) {
587
- def rec (tp : Type , mixins : List [Type ]): List [Typ ] = tp.dealias match {
587
+ def rec (tp : Type , mixins : List [Type ]): List [Type ] = tp.dealias match {
588
588
case AndType (tp1, tp2) =>
589
- def decomposeComponent (tpA : Type , tpB : Type ): List [Typ ] =
590
- rec(tpA, tpB :: mixins).flatMap {
591
- case Typ (tp, _) =>
592
- if tp <:< tpB then
593
- Typ (tp, decomposed = true ) :: Nil
594
- else if tpB <:< tp then
595
- Typ (tpB, decomposed = true ) :: Nil
596
- else if TypeComparer .provablyDisjoint(tp, tpB) then
597
- Nil
598
- else
599
- Typ (AndType (tp, tpB), decomposed = true ) :: Nil
589
+ def decomposeComponent (tpA : Type , tpB : Type ): List [Type ] =
590
+ rec(tpA, tpB :: mixins).collect {
591
+ case tp if tp <:< tpB => tp
592
+ case tp if tpB <:< tp => tpB
593
+ case tp if ! TypeComparer .provablyDisjoint(tp, tpB) => AndType (tp, tpB)
600
594
}
601
595
602
596
if canDecompose(tp1) then
603
597
decomposeComponent(tp1, tp2)
604
598
else
605
599
decomposeComponent(tp2, tp1)
606
600
607
- case OrType (tp1, tp2) => List (Typ ( tp1, decomposed = true ), Typ ( tp2, decomposed = true ) )
601
+ case OrType (tp1, tp2) => List (tp1, tp2)
608
602
case tp if tp.isRef(defn.BooleanClass ) =>
609
603
List (
610
- Typ ( ConstantType (Constant (true )), decomposed = true ),
611
- Typ ( ConstantType (Constant (false )), decomposed = true )
604
+ ConstantType (Constant (true )),
605
+ ConstantType (Constant (false ))
612
606
)
613
607
case tp if tp.isRef(defn.UnitClass ) =>
614
- Typ ( ConstantType (Constant (())), decomposed = true ) :: Nil
608
+ ConstantType (Constant (())) :: Nil
615
609
case tp if tp.classSymbol.isAllOf(JavaEnumTrait ) =>
616
- tp.classSymbol.children.map(sym => Typ (sym .termRef, decomposed = true ) )
610
+ tp.classSymbol.children.map(_ .termRef)
617
611
618
612
case tp @ AppliedType (tycon, targs) if tp.classSymbol.children.isEmpty && canDecompose(tycon) =>
619
613
// It might not obvious that it's OK to apply the type arguments of a parent type to child types.
620
614
// But this is guarded by `tp.classSymbol.children.isEmpty`,
621
615
// meaning we'll decompose to the same class, just not the same type.
622
616
// For instance, from i15029, `decompose((X | Y).Field[T]) = [X.Field[T], Y.Field[T]]`.
623
- rec(tycon, Nil ).map(typ => Typ ( tp.derivedAppliedType(typ.tp , targs), decomposed = true ))
617
+ rec(tycon, Nil ).map(tp.derivedAppliedType(_ , targs))
624
618
625
619
case tp : NamedType if canDecompose(tp.prefix) =>
626
- rec(tp.prefix, Nil ).map(typ => Typ ( tp.derivedSelect(typ.tp), decomposed = true ) )
620
+ rec(tp.prefix, Nil ).map(tp.derivedSelect)
627
621
628
622
case tp =>
629
623
def getChildren (sym : Symbol ): List [Symbol ] =
@@ -655,9 +649,9 @@ object SpaceEngine {
655
649
656
650
debug.println(i " $tp decomposes to $parts" )
657
651
658
- parts.map( Typ (_, decomposed = true ))
652
+ parts
659
653
}
660
- rec(tp, Nil )
654
+ rec(tp, Nil ).map( Typ (_, decomposed = true ))
661
655
}
662
656
663
657
/** Abstract sealed types, or-types, Boolean and Java enums can be decomposed */
0 commit comments