-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Empty package visibility underspecified or just confusing #7891
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 vote for:
|
Are there many things in the language where the current compilation unit matters (outside of the obvious We've had this discussion before (and I can't remember about what exactly) but, personally, while I can appreciate that it would be a bit of a stutter step if as soon as you introduced That's why I ask: should I just come to terms with the fact that this detail matters? |
(Found it, it was to do with imports: scala/bug#11593) |
@dwijnand There's an old scala2 ticket where paulp was pulling his hair out about this stuff. (Number 9552.) Tooling can assist, but ultimately, the answer to "I can't reason about this" is "Don't write code that way." Prefer FP to OOP, composition to inheritance, etc. The empty package and top-level defs is worth attention because, as a newbie, I'm likely to be trying out code that is the opposite of best practice. Another recent idea, which I haven't promoted, is to enable denotating a directory of files as a single compilation unit, |
I consider defining multiple packages within a file to be quite an advanced feature, don't you? As such, I don't think the newbie excuse holds. |
Here, it told me to add the braces, and then I added the f after new. It didn't tell me not to use new. I could have switched the order of the main and package. Obviously, this test throws.
|
As a beginner why did you introduce a package block? |
As a non-beginner but as a Scala 2 refugee, I tried:
whereas I might have done better with
I usually put experimental classes in packages so they wind up in subdirs of my snippets dir. |
I only just caught up with this change in behavior because https://github.com/lampepfl/dotty/blob/release-3.1.1/tests/untried/neg/warn-unused-imports.scala#L9 no longer compiles. The implementation wound up reversing the previous vote from Jan 2020, that empty package definitions would be in scope in the same file. |
minimized code
Compiled together or separately:
expectation
Binding of
f
shouldn't depend on compilation unit, but moreover, members of the empty package should be visible only to members of the empty package; or specify that they are visible in the current compilation unit.Other restrictions may apply. Cf #7650
Related confusion in Scala 2: scala/bug#10927
The text was updated successfully, but these errors were encountered: