Skip to content

Separate compilation violates package-protected accessibility #12321

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

Closed
eed3si9n opened this issue Jan 23, 2021 · 2 comments · Fixed by scala/scala#9454
Closed

Separate compilation violates package-protected accessibility #12321

eed3si9n opened this issue Jan 23, 2021 · 2 comments · Fixed by scala/scala#9454

Comments

@eed3si9n
Copy link
Member

This is a retroactive bug report on Scala 2.12.x and 2.13.0 ~ 1 since it seems to be fixed in Scala 2.13.2.

reproduction steps

using Scala 2.13.1

bar/B.scala

package bar

protected[bar] class B(x: Int)

foo/Test.scala

package example

import bar.B

object Test {
  def b = new B(1)
}

bash

mkdir -p bar/classes/
mkdir -p foo/classes/
$HOME/Applications/scala-2.13.1/bin/scalac bar/B.scala -d bar/classes
ls bar/classes/bar
# outputs B.class

$HOME/Applications/scala-2.13.1/bin/scalac -cp bar/classes/ foo/Test.scala -d foo/classes
ls foo/classes/example
# outputs Test$.class  Test.class

problem

The separate compilation violates protected[bar].

expectation

Test should not compile.

foo/Test.scala:6: error: not found: type B
  def b = new B(1)
              ^
1 error

note

If I compile all sources together the accessibility is checked correctly:

$ $HOME/Applications/scala-2.13.1/bin/scalac bar/B.scala  foo/Test.scala -d foo/classes
foo/Test.scala:6: error: not found: type B
  def b = new B(1)
              ^
one error found

keyword for search

visibility

@som-snytt
Copy link

Duplicates #8121 which also turns on an import and separate compilation.

Fix was scala/scala#8753

I thought there was a similar "qualified access" ticket, but maybe not. It deserves a regression test, since Lukas feared side effects of symbol forcing, but I don't think he necessarily anticipated that other checks would start to work correctly.

@eed3si9n
Copy link
Member Author

@som-snytt Thanks for the pointers!

Here's a PR for tests - scala/scala#9453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants