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

Replace import $file syntax with flat package namespacing #4462

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

lihaoyi
Copy link
Member

@lihaoyi lihaoyi commented Feb 3, 2025

Fixes #4459
Fixes #3894

With this PR, all .mill files in a folder are in the same flat package namespace, similar to how normal Scala files work. The previous import $file syntax was inherited from Ammonite, and unfortunately never took off across the Scala community. In effect this makes .mill files behave almost exactly like .scala files, which is part of the longer term goal of removing special handling for .mill files.

The code generation for the helper files is not changed at all in this PR, rather we just make use of Scala 3's export clauses to make them available under the main build.mill/package.mill file as well

There is the caveat that the package objects in .mill files can be referenced via build.foo.bar without the trailing .package. Implementing this caveat is the cause of a lot of the hackiness in the codegen, which will hopefully go away once the upstream language feature lands scala/improvement-proposals#100

We leave the codegenned import _root_.{build_ => $file} in place so import $file will continue to work to ease in the migration, but are no longer the recommended way of referencing helper files

@lihaoyi lihaoyi marked this pull request as ready for review February 3, 2025 13:29
@lihaoyi lihaoyi changed the title Remove import $file syntax in favor of direct namespacing Replace import $file syntax with flat package namespacing Feb 4, 2025
@lihaoyi lihaoyi merged commit 598aaea into com-lihaoyi:main Feb 4, 2025
30 of 31 checks passed
@lefou lefou added this to the 0.13.0 milestone Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide an alternative to import $file Consolidate import $file.foo.bar into build.foo.bar namespace
2 participants