-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 import x.{*, given}
under -Xsource:3
#9724
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about import x.{foo, *, given}
, when you need to name foo
to give it higher precedence in name shadowing? You can split into two imports, but perhaps it would be better to avoid the problem?
Other than that LGTM.
That should work too |
Oh, I guess that already works ("duration.{Duration as D, given, *}"). But are those two meant to always be next to each other? What if I like alphabetic ordering and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still curious, but less concerned.
That's required by this implementation yes, doing something more general is a bit tricky because we need to avoid triggering the deprecation warning for given as an identifier at the same time |
Imagine a Scala 3 library containing: ``` object A { val a: Int = 1 given b: Int = 2 } ``` To import all members of `A` from Scala 2, we write `import A.*`, but to do the same from Scala 3, we need to write `import A.{*, given}` instead. This complicates cross-compilation for projects which depend on Scala 3 libraries (unless these libraries exclusively use `implicit` which is not something we want to encourage). This commit remedies this by allowing `import x.{*, given}` (and `import x.{given, *}`), this is easy to do since we can just pretend the user wrote `import x.*` which will give us both regular and given members in Scala 2 code and therefore match the semantics of Scala 3.
#9722 was changed to not warn when referring to an identifier called |
import x.{*, given}
under -Xsource:3 import x.{*, given}
under -Xsource:3
Note: This PR sits on top of #9722 but could be made independent if needed.
Imagine a Scala 3 library containing:
To import all members of
A
from Scala 2, we writeimport A.*
,but to do the same from Scala 3, we need to write
import A.{*, given}
instead. This complicates cross-compilation for projects which depend on
Scala 3 libraries (unless these libraries exclusively use
implicit
which is not something we want to encourage).
This commit remedies this by allowing
import x.{*, given}
(andimport x.{given, *}
), this is easy to do since we can just pretend the userwrote
import x.*
which will give us both regular and given members inScala 2 code and therefore match the semantics of Scala 3.