Skip to content

Missing access checks when accessing package private classes #3339

Closed
@smarter

Description

@smarter

This code shouldn't compile:

package outer {
  private class A

  package inner {
    object Test {
      def main(args: Array[String]): Unit = {
        println(new A)
      }
    }
  }
}

Because if you try to run it you get:

% dotr outer.inner.Test
Exception in thread "main" java.lang.IllegalAccessError: tried to access class outer.A from class outer.inner.Test$
        at outer.inner.Test$.main(i3302.scala:7)
        at outer.inner.Test.main(i3302.scala

This code compiles and run with scalac because the class A is emitted as public whereas dotty emits it as private.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions