Skip to content

protected inner Java classes parsed from classfiles lack package boundary #10786

@hrhino

Description

@hrhino
hhoughton:tmp hhoughton$ cat > Test.java
package pkg;

public class Test { protected static class Inner {} }
hhoughton:tmp hhoughton$ javac -d . Test.java
hhoughton:tmp hhoughton$ scala-launch 2.12.4 -cp .
Welcome to Scala 2.12.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_161).
Type in expressions for evaluation. Or try :help.

scala> :pow
Power mode enabled. :phase is at typer.
import scala.tools.nsc._, intp.global._, definitions._
Try :help or completions for vals._ and power._

scala> typeOf[_root_.pkg.Test].companion.decl(TypeName("Inner")).privateWithin
res0: $r.intp.global.Symbol = <none>

This means that you can't access it in the same package:

hhoughton:tmp hhoughton$ scalac-launch 2.12.4 -cp . Use.scala
Use.scala:3: error: class Inner in object Test cannot be accessed in object pkg.Test
 Access to protected class Inner not permitted because
 enclosing package pkg is not a subclass of
 object Test in package pkg where target is defined
object Use extends Test.Inner
                        ^
one error found

Note that mixed compilation works as expected:

hhoughton:tmp hhoughton$ scalac-launch 2.12.4 Use.scala Test.java
hhoughton:tmp hhoughton$ echo $?
0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions