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

Allow import x.{*, given} under -Xsource:3 #9724

Merged
merged 1 commit into from Aug 25, 2021
Merged

Conversation

smarter
Copy link
Member

@smarter smarter commented Aug 10, 2021

Note: This PR sits on top of #9722 but could be made independent if needed.


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.

@scala-jenkins scala-jenkins added this to the 2.13.7 milestone Aug 10, 2021
Copy link
Member

@dwijnand dwijnand left a 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.

@smarter
Copy link
Member Author

smarter commented Aug 10, 2021

That should work too

@dwijnand
Copy link
Member

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 import x.{given, someNameAfterG, *}?

Copy link
Member

@dwijnand dwijnand left a 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.

@smarter
Copy link
Member Author

smarter commented Aug 10, 2021

But are those two meant to always be next to each other?

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

@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Aug 10, 2021
@smarter smarter marked this pull request as draft August 17, 2021 15:10
@smarter smarter self-assigned this Aug 17, 2021
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.
@smarter
Copy link
Member Author

smarter commented Aug 24, 2021

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

#9722 was changed to not warn when referring to an identifier called given, so I've been able to simplify this PR and make it work with import x.{given, someNameAfterG, *} too.

@smarter smarter marked this pull request as ready for review August 24, 2021 16:21
@smarter smarter assigned dwijnand and unassigned smarter Aug 24, 2021
@smarter smarter requested a review from dwijnand August 24, 2021 16:57
@lrytz lrytz merged commit 8bbc323 into scala:2.13.x Aug 25, 2021
@SethTisue SethTisue changed the title Allow import x.{*, given} under -Xsource:3 Allow import x.{*, given} under -Xsource:3 Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
5 participants