-
Notifications
You must be signed in to change notification settings - Fork 14
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
Allow customizing root imports #474
Comments
I don't have a comprehensive view of scalac's options, but the fact that |
For |
I'd like to stir up some discussion about the As the feature is envisioned now, I can imagine scenarios in which updating to a binary-compatible library could break lots of source code. Even changing the order of the What is the feature really trying to solve? Does it aim to provide a nice way to import things at use-site without the user knowing much about the organisation of the library? If this is the case, it's worth researching how we could address this problem with external tooling. For example, what if library authors could write typechecked templates (via a macro or a compiler plugin) and then have IDEs automatically import them? What if the recommended imports (that would be represented via |
Anytime you use import some.lib._ what is in scope is already determined by some.lib and can change when upgrading versions. This doesn’t feel like a new risk to me for most use cases. It would allow a library to restructure it’s internals without causing a breakage or needing a user side migration which seems like as much a benefit as a risk. Hopefully others will chime in but to my mind the two important usages of an export type functionality are:
Personally this also changes how I organize code. I end up putting logic in my companions that I would not otherwise just to get the “free import” from the companion object. |
Sure, but the point I'm trying to make is that in the |
My simple implementation (simplementation) is over on scala/scala#5339. All it supports is That PR implements the level 4 name binding rule; to make that work usefully, it also introduces a "rule" that preamble imports are also level 4 precedence. That means they can't introduce ambiguities in user code, which is how it works now. On another ticket or PR, @fommil mentions that the typelevel feature can introduce ambiguities. The intuition is that if I can't see it in my code, make it a lower precedence so it only pops up when I need it. Otherwise, the rules for shadowing are unchanged. One case where it matters is for symbols in my package but not defined in my file: ordinary imports (at level 2 or 3) would create an ambiguity. Level 2 and 3 correspond to specific and wildcard imports; but preamble imports are always wildcard and always level 4. |
The implementing PR for Closing this in favor of the linked ticket for simplifying import syntax and maybe adding export. |
Summary of the discussion in scala/scala#5350:
-Ysysdef
and-Ypredef
and-Yno-predef
and-Yno-imports
-Yimports:scala._,scala.Predef._
, requires fully qualified imports (like if they all started with_root_.
).-Yimports:_
for none. Colon-syntax usingMultiStringSetting
.Predef.x
in a source file removes the implicitscala.Predef._
import from that file. This is current behavior, and it will stay.-Yimports
is present and includesscala.Predef._
-- this can still be debated (comment)-Ysysdef
and-Ypredef
-Yimports
cannot be un-imported in individual files (things likeimport Predef.{_ => _}
orimport scala.{util => _, _}
) -- maybe this can still be considered. For predefy-style imports it can be done by importing a single member that's not actually used.Aftermath:
It also sounds like an
export
feature as outlined here is universally welcomed. There is (probably?) still a chance to get this in 2.13 if someone takes the lead. It should be coordinated with #442 (ideas to simplify imports).The text was updated successfully, but these errors were encountered: