Skip to content

Commit

Permalink
Space: Make isDecomposableToChildren ignore type constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand authored and Kordyjan committed Aug 9, 2023
1 parent c569a4f commit 518c020
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ object SpaceEngine {
// For instance, from i15029, `decompose((X | Y).Field[T]) = [X.Field[T], Y.Field[T]]`.
parts.map(tp.derivedAppliedType(_, targs))

case tp if tp.classSymbol.isDecomposableToChildren =>
case tp if tp.isDecomposableToChildren =>
def getChildren(sym: Symbol): List[Symbol] =
sym.children.flatMap { child =>
if child eq sym then List(sym) // i3145: sealed trait Baz, val x = new Baz {}, Baz.children returns Baz...
Expand Down Expand Up @@ -678,8 +678,8 @@ object SpaceEngine {
rec(tp, Nil)
}

extension (cls: Symbol)
/** A type is decomposable to children if it's sealed,
extension (tp: Type)
/** A type is decomposable to children if it has a simple kind, it's sealed,
* abstract (or a trait) - so its not a sealed concrete class that can be instantiated on its own,
* has no anonymous children, which we wouldn't be able to name as counter-examples,
* but does have children.
Expand All @@ -688,7 +688,8 @@ object SpaceEngine {
* A sealed trait with subclasses that then get removed after `refineUsingParent`, decomposes to the empty list.
* So that's why we consider whether a type has children. */
def isDecomposableToChildren(using Context): Boolean =
cls.is(Sealed) && cls.isOneOf(AbstractOrTrait) && !cls.hasAnonymousChild && cls.children.nonEmpty
val cls = tp.classSymbol
tp.hasSimpleKind && cls.is(Sealed) && cls.isOneOf(AbstractOrTrait) && !cls.hasAnonymousChild && cls.children.nonEmpty

val ListOfNoType = List(NoType)
val ListOfTypNoType = ListOfNoType.map(Typ(_, decomposed = true))
Expand Down

0 comments on commit 518c020

Please sign in to comment.