Skip to content

Commit cad41d2

Browse files
committed
Fix #3339: Disallow accesses to private package members from nested pkgs
Change of the accessibility rules: Disallow accesses to private package members from nested packages. Such accesses were causing an access error at runtime before.
1 parent be50d2c commit cad41d2

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,7 @@ object SymDenotations {
674674
final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer = null)(implicit ctx: Context): Boolean = {
675675

676676
/** Are we inside definition of `boundary`? */
677-
def accessWithin(boundary: Symbol) =
678-
ctx.owner.isContainedIn(boundary) &&
679-
(!(this is JavaDefined) || // disregard package nesting for Java
680-
ctx.owner.enclosingPackageClass == boundary.enclosingPackageClass)
677+
def accessWithin(boundary: Symbol) = ctx.owner.isContainedIn(boundary)
681678

682679
/** Are we within definition of linked class of `boundary`? */
683680
def accessWithinLinked(boundary: Symbol) = {
@@ -733,7 +730,9 @@ object SymDenotations {
733730
( !(this is Local)
734731
|| (owner is ImplClass) // allow private local accesses to impl class members
735732
|| isCorrectThisType(pre)
736-
)
733+
) &&
734+
(!(this.is(Private) && owner.is(Package)) ||
735+
owner == ctx.owner.enclosingPackageClass)
737736
|| (this is Protected) &&
738737
( superAccess
739738
|| pre.isInstanceOf[ThisType]

0 commit comments

Comments
 (0)