-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Document behaviour of private modifier for top level classes #11323
Comments
There's at least a difference for Scala.js: a protected thing can be exported to JavaScript (e.g., with |
@sjrd Thank you for telling me quickly and in detail! |
Probably not, no. |
The error you get in Scala 2 is i11336.scala:10: error: private class Private escapes its defining scope as part of type pkg.Private
def createPrivate : Private = ???//new Private() // Error in Scala 2, but OK in Scala 3 If |
@odersky I wondered if this constraint was removed from private, it would be treated the same as protected. |
private[pkg] class Private Private leakage checks are not done for package private and qualified private members. Only regular object-private members are checked. That explains the discrepancy with Scala 2. I tried to make package-private members be checked also but that causes lots of tests to fail, so it would be too risky to do. An alternative is to change the encoding; keep |
This should probably go to a different repo about spec changes. |
@odersky Thank you for your polite explanation. I learned that in Scala 3, it can change considerably to private[this] or private[pkg] depending on where private appears. |
Another design dimension is "private to empty package". At #13114 I noticed it's possible to access empty package defs in a different file, if a.scalaprivate class C b.scalaprivate class X // arbitrary It might be useful if an unpackaged (empty-packaged) top-level def could be scoped to current file by making it private. That is more useful if it's not visible in empty package in other files. There can be no qualified private for empty package, presumably |
I referred to #7780.
In Scala 3, A private global class in the field or return type of a method,
I interpreted that the members themselves do not need to be kept private.
So, I think that protected and private in the global class have the same meaning.
Is this correct?
The text was updated successfully, but these errors were encountered: