Skip to content

Commit b396ee5

Browse files
committed
Fix #23113: Treat private classes as sealed
1 parent dec859f commit b396ee5

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ object SymDenotations {
17351735
c.ensureCompleted()
17361736
end completeChildrenIn
17371737

1738-
if is(Sealed) || isAllOf(JavaEnum) && isClass then
1738+
if (is(Sealed) || is(Private) || isAllOf(JavaEnum)) && isClass then
17391739
if !is(ChildrenQueried) then
17401740
// Make sure all visible children are completed, so that
17411741
// they show up in Child annotations. A possible child is visible if it

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,7 +975,7 @@ class Namer { typer: Typer =>
975975
val sym = denot.symbol
976976

977977
def register(child: Symbol, parentCls: ClassSymbol) = {
978-
if (parentCls.is(Sealed))
978+
if (parentCls.is(Sealed) || parentCls.is(Private))
979979
if ((child.isInaccessibleChildOf(parentCls) || child.isAnonymousClass) && !sym.hasAnonymousChild)
980980
addChild(parentCls, parentCls)
981981
else if (!parentCls.is(ChildrenQueried))

tests/pos/i23113.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//> using options -Werror
2+
3+
object Repro {
4+
sealed abstract class Listener
5+
6+
final case class Empty()
7+
extends Listener
8+
9+
final case class Waiting(next: Promise)
10+
extends Listener
11+
12+
def foo[A](l: Listener): Unit = {
13+
l match {
14+
case Empty() => ()
15+
case w @ Waiting(_) => ()
16+
}
17+
}
18+
}
19+
20+
sealed trait Promise
21+
22+
object Promise {
23+
24+
def apply(): Promise = new PromiseImpl()
25+
26+
private abstract class PromiseBase extends Promise
27+
28+
private final class PromiseImpl() extends PromiseBase
29+
}

0 commit comments

Comments
 (0)