-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Missing access checks when accessing package private classes #3339
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
Comments
I think the code is legal, so we need to do like scalac and make class A public. |
@odersky If I understand correctly, this will break a lot of code. The following pattern will not compile anymore package collection
package immutable
private[collection] class HashMapCollision1
class Test {
new HashMapCollision1 // error: not accessible
} The boundary for |
I also fear it will break a lot of code. @retronym do you think we can pull it off regardless? Note that -language:Scala2 is too weak here. If we compile a private class with the new scheme, we cannot access it anymore from nested packages even if -language:Scala2 is enabled. |
It would certainly be a big change. The example above would be best solved by: package collection {
package internal {
class HashMapCollision1
}
package immutable {
object Test { new internal.HashMapCollision1 }
}
} In which the JPMS module declaration for scala-library did not export Alternatively, we could add a different syntax for Java-style package-protected classes. Could we change the meaning of |
Note that Since we did not run into the issue with |
Fix #3339: Disallow accesses to private package members from nested pkgs
This code shouldn't compile:
Because if you try to run it you get:
This code compiles and run with scalac because the class
A
is emitted aspublic
whereas dotty emits it asprivate
.The text was updated successfully, but these errors were encountered: