Skip to content

Commit f4e6239

Browse files
authored
Make opaque types decomposable (#24068)
fixes: #22513 Currently, if the upper bounds of opaque types are sealed, they pass exhaustivityCheckable, but exhaustivity checks are not handled correctly because the compiler preventing from decomposing them. The guard was introduced in [#19368](#19368), but the tests still pass even without this guard.
1 parent 71fcd1a commit f4e6239

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -717,14 +717,12 @@ object SpaceEngine {
717717

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

729727
val ListOfNoType = List(NoType)
730728
val ListOfTypNoType = ListOfNoType.map(Typ(_, decomposed = true))

tests/pos/i22513.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
opaque type R[T] <: T = T
2+
3+
object Test {
4+
enum E:
5+
case A(a: Int)
6+
7+
val v: R[E] = ???
8+
v match
9+
case E.A(_) =>
10+
}
11+
12+
sealed trait Foo
13+
14+
case class FooA() extends Foo
15+
case class FooB() extends Foo
16+
17+
object O {
18+
opaque type OpaqueFoo <: Foo = Foo
19+
def fooB(): OpaqueFoo = FooB()
20+
}
21+
22+
@main def main =
23+
val p: O.OpaqueFoo = O.fooB()
24+
25+
p match
26+
case _: FooA => println("fooA")
27+
case _: FooB => println("fooB")

0 commit comments

Comments
 (0)