-
Notifications
You must be signed in to change notification settings - Fork 21
Empty package object #10927
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's not obvious that members of the empty package are visible to members of packagings, although ordinary lexical scoping seems to suggest obviously yes:
In separate files, the class is visible to All this is contrary to Java, where members of the empty package are visible only to other members of the empty package, which is a kind of scratch space for experiments but must never accidentally leak into real code. Similarly, the following works
Not sure if that was the point of the original issue, but it's clearly wrong. It seems to me there is nothing extraordinary about a package object for the empty package. The problem is that access to the empty package is bungled in a couple of ways, both to top-level members and members of the package object. Spec says: Top-level definitions outside a packaging are assumed to be injected into a special empty package. That package cannot be named and therefore cannot be imported. However, members of the empty package are visible to each other without qualification. I wonder what doti says. |
I corrected the last example, which scalac compiles together but not separately. dotc also compiles them separately. |
Per odersky no sane person does that. These are REPL use cases, and no one uses the REPL that way anyway. |
Uh oh!
There was an error while loading. Please reload this page.
If I create a package object in the empty package:
then I have to import its members explicitly:
If the empty package is allowed to have a package object, then the workaround also bends the rule that members of the empty package cannot be imported.
Edit: obviously this is more interesting if they're importing in a named package. Also, same behavior on dotty.
The text was updated successfully, but these errors were encountered: