Skip to content

Commit 3849032

Browse files
authored
Merge pull request #621 from scala/backport-lts-3.3-24068
Backport "Make opaque types decomposable" to 3.3 LTS
2 parents bcb949d + 7209eb7 commit 3849032

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)