From e00caba82c53d5b2c6f755f752653473bc1e9dac Mon Sep 17 00:00:00 2001 From: Yoonjae Jeon Date: Thu, 25 Sep 2025 16:08:18 +0900 Subject: [PATCH 1/2] Make opaque types decomposable --- .../tools/dotc/transform/patmat/Space.scala | 1 - tests/pos/i22513.scala | 27 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i22513.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 7857f8c86189..49138c7aa3aa 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -724,7 +724,6 @@ object SpaceEngine { && 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)) diff --git a/tests/pos/i22513.scala b/tests/pos/i22513.scala new file mode 100644 index 000000000000..2cf2bc58227a --- /dev/null +++ b/tests/pos/i22513.scala @@ -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") From 4224938dddc9a819796a98c2f7e8acd97849b5cd Mon Sep 17 00:00:00 2001 From: Yoonjae Jeon Date: Fri, 3 Oct 2025 20:39:00 +0900 Subject: [PATCH 2/2] address review --- compiler/src/dotty/tools/dotc/transform/patmat/Space.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 49138c7aa3aa..685721b7d575 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -717,7 +717,6 @@ 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)