-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Meaning of private toplevel definitions #7780
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
It should have exactly the same visibility as a |
No, |
Speaking from the peanut gallery -- to me, private to the package seems more intuitively obvious, since my understanding of top-level declarations is that they are generally scoped relative to the package itself. That's not exactly a principled argument, but it's one data point of expectations... |
I always thought that |
Hello! Some aggregated thoughts: In favor of file visibility:
In favor of package visibility:
Now, I feel 55%/45% bias towards the file visibility for the top level definitions (including private classes). Looks like small but strategically good change. |
We have only two choices:
The reason is that package p
private val x = e
class C { ... } is translated to package p
object ...$package {
private[p] val x = e
}
class C { ... } We could drop the Arguments in favor of dropping
Arguments against:
My tentative position is that it's better to leave things as they are. I.e. |
Relatedly, inclusion of nested things is weird. Here,
I recently asked about I'm not sure which emoji reaction to use for the poll, but I vote for changing status quo to "wow, access modifiers are really interesting in Scala 3." |
As I said in the beginning, to me it's pretty obvious that a Regularity wrt the scope of opaque type aliases would be nice, but infinitely les important than regularity with the visibility of classes. |
It looks like Scala 2 and 3 don't have the same opinion of where a private class should be visible actually: // A.scala:
package pkg
private class A
// B.scala:
package pkg
class B extends A % scalac A.scala B.scala Scala 2: B.scala:3: error: private class A escapes its defining scope as part of type pkg.A
class B extends A
^
1 error Scala 3:
|
Oops nevermind, I misread the error which is about the private scope leaking, not about A not being visible. So in both cases A is visible in separate compilation units in the same package. |
@odersky (Actually, such a scope already exists for |
I agree that private defs should behave like private classes, and private classes should behave like Scala 2. That is what is implemented, so no action is needed. |
What should the visibility of
x
defined a toplevel definition likebe ? Currently it is the package
p
. But we could also decide that it should be the file in whichx
appears.The text was updated successfully, but these errors were encountered: