Skip to content

Commit 7209eb7

Browse files
nox213tgodzik
authored andcommitted
Make opaque types decomposable (scala#24068)
fixes: scala#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 [scala#19368](scala#19368), but the tests still pass even without this guard. [Cherry-picked f4e6239]
1 parent 269f186 commit 7209eb7

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
@@ -695,14 +695,12 @@ object SpaceEngine {
695695

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

707705
val ListOfNoType = List(NoType)
708706
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)