From 518c02055f3addd2b4ea08ebaa6ac9c3ae65392e Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 1 Aug 2023 14:47:31 +0100 Subject: [PATCH] Space: Make isDecomposableToChildren ignore type constructors --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 002e3646c663..467b36df3805 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -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... @@ -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. @@ -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))