Skip to content

Treat packages as flat when access checking Java-defined symbols #11618

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 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,12 @@ object SymDenotations {
*/
final def isAccessibleFrom(pre: Type, superAccess: Boolean = false, whyNot: StringBuffer = null)(using Context): Boolean = {

/** Are we inside definition of `boundary`? */
def accessWithin(boundary: Symbol) = ctx.owner.isContainedIn(boundary)
/** Are we inside definition of `boundary`?
* If this symbol is Java defined, package structure is interpreted to be flat.
*/
def accessWithin(boundary: Symbol) =
ctx.owner.isContainedIn(boundary)
&& !(is(JavaDefined) && boundary.is(PackageClass) && ctx.owner.enclosingPackageClass != boundary)

/** Are we within definition of linked class of `boundary`? */
def accessWithinLinked(boundary: Symbol) = {
Expand Down Expand Up @@ -2209,8 +2213,8 @@ object SymDenotations {
ensureCompleted()
myCompanion

override def registeredCompanion_=(c: Symbol) =
myCompanion = c
override def registeredCompanion_=(c: Symbol) =
myCompanion = c

private var myNestingLevel = -1

Expand Down
8 changes: 8 additions & 0 deletions tests/neg/i11616/A.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package pkg;

public class A {

protected void fn1() { System.out.println("A#fn1()"); }
void fn2() { System.out.println("A#fn2()"); }

}
16 changes: 16 additions & 0 deletions tests/neg/i11616/B.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package pkg.sub

import pkg.A

class B extends A {

def test(): Unit = {
super.fn1()
super.fn2() // error: cannot be acesssed

val b: B = new B()
b.fn1()
b.fn2() // error: cannot be acesssed
}

}