Skip to content

Fix #3339: Disallow accesses to private package members from nested pkgs #3735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -674,10 +674,7 @@ object SymDenotations {
final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer = null)(implicit ctx: Context): Boolean = {

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

/** Are we within definition of linked class of `boundary`? */
def accessWithinLinked(boundary: Symbol) = {
Expand Down Expand Up @@ -733,7 +730,9 @@ object SymDenotations {
( !(this is Local)
|| (owner is ImplClass) // allow private local accesses to impl class members
|| isCorrectThisType(pre)
)
) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This long chain of conditions is getting really hard to read, factor it out into a few vals?

Copy link
Contributor Author

@odersky odersky Jan 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried but it does not seem to help. The key is treating !A || B as an implication, then things get clearer. I was wondering whether we should add an inline helper method implies on Boolean to do this. But it's quite a lot of effort.

(!(this.is(Private) && owner.is(Package)) ||
owner == ctx.owner.enclosingPackageClass)
|| (this is Protected) &&
( superAccess
|| pre.isInstanceOf[ThisType]
Expand Down