Skip to content

Commit ac7e574

Browse files
committed
Fix #5831: types in parent visible in child under Scala2
1 parent 00fbf27 commit ac7e574

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1680,9 +1680,12 @@ object SymDenotations {
16801680
val denots1 = collect(denots, ps)
16811681
p.classSymbol.denot match {
16821682
case parentd: ClassDenotation =>
1683+
val parentDenots =
1684+
// Scala2 compatibility: private types are visible in children, see i5831.scala
1685+
if (name.isTypeName && ctx.scala2Setting) parentd.membersNamed(name)
1686+
else parentd.nonPrivateMembersNamed(name)
16831687
denots1 union
1684-
parentd.nonPrivateMembersNamed(name)
1685-
.mapInherited(ownDenots, denots1, thisType)
1688+
parentDenots.mapInherited(ownDenots, denots1, thisType)
16861689
case _ =>
16871690
denots1
16881691
}

tests/pos-scala2/i5831.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait Matchers { matchers =>
2+
private sealed trait Collected
3+
def foo(collected: Collected): Int = 3
4+
}
5+
object Matchers extends Matchers

0 commit comments

Comments
 (0)