Skip to content
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

Expand value references to packages to their underlying package objects #22011

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Nov 22, 2024

A package object can be seen as the facade of a package. For instance, it is the logical place where we want to write doc comments that explain a package.

So far references to packages cannot be used as values. But if the package has a package object, it would make sense to allow the package reference with the meaning that it refers to this object. For instance, let's say we have

package a
object b

Of course, we can use a.b as a value. But if we change that to

package a
package object b

we can't anymore. This PR changes that so that we still allow a reference a.b as a value to mean the package object. Due to the way package objects are encoded the a.b reference expands to a.b.package.

@odersky odersky marked this pull request as draft November 22, 2024 16:05
@tgodzik tgodzik added needs-minor-release This PR cannot be merged until the next minor release area:experimental and removed needs-minor-release This PR cannot be merged until the next minor release labels Nov 25, 2024
A package object can be seen as the facade of a package. For instance, it is the logical
place where we want to write doc comments that explain a package.

So far references to packages cannot be used as values. But if the package has a package
object, it would make sense to allow the package reference with the meaning that it refers
to this object. For instance, let's say we have

```scala
package a
object b
```
Of course, we can use `a.b` as a value. But if we change that to
```scala
package a
package object b
```
we can't anymore. This PR changes that so that we still allow a reference `a.b`
as a value to mean the package object. Due to the way package objects are encoded
the `a.b` reference expands to `a.b.package`.
@odersky odersky force-pushed the add-package-object-values branch from 97fa8ff to f6c6dfa Compare November 25, 2024 17:54
 - Instead of "Dropped: package objects" have a new doc page "Toplevel Definitions"
   in "other new features".
 - Add a doc page for experimental reference-able package object, which uses some
   wording from the Pre-SIP.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants