Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/patmat/Space.scala
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,12 @@ object SpaceEngine {

extension (tp: Type)
def isDecomposableToChildren(using Context): Boolean =
val sym = tp.typeSymbol // e.g. Foo[List[Int]] = type Foo (i19275)
val cls = tp.classSymbol // e.g. Foo[List[Int]] = class List
tp.hasSimpleKind // can't decompose higher-kinded types
&& cls.is(Sealed)
&& cls.isOneOf(AbstractOrTrait) // ignore sealed non-abstract classes
&& !cls.hasAnonymousChild // can't name anonymous classes as counter-examples
&& cls.children.nonEmpty // can't decompose without children
&& !sym.isOpaqueAlias // can't instantiate subclasses to conform to an opaque type (i19275)

val ListOfNoType = List(NoType)
val ListOfTypNoType = ListOfNoType.map(Typ(_, decomposed = true))
Expand Down
27 changes: 27 additions & 0 deletions tests/pos/i22513.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
opaque type R[T] <: T = T

object Test {
enum E:
case A(a: Int)

val v: R[E] = ???
v match
case E.A(_) =>
}

sealed trait Foo

case class FooA() extends Foo
case class FooB() extends Foo

object O {
opaque type OpaqueFoo <: Foo = Foo
def fooB(): OpaqueFoo = FooB()
}

@main def main =
val p: O.OpaqueFoo = O.fooB()

p match
case _: FooA => println("fooA")
case _: FooB => println("fooB")
Loading