Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented May 29, 2024

Fixes scala/bug#12999

Under -Xsource:3, instead of ignoring import x.given, use it to import implicits only. Take import x.{given, *} as import x.*.

Although import x.* will import "legacy implicits" under Scala 3 migration rules, it's desirable to express just import x.given and have it work in Scala 2..

Import by type is not supported.

The selector is encoded as if it were _ as given.

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone May 29, 2024
@som-snytt
Copy link
Contributor Author

spurious spec failure

@som-snytt
Copy link
Contributor Author

som-snytt commented May 30, 2024

add test for import x.{y as _, given, *} where y is implicit. Then you can't reduce to import x.{y as _, *}.

Edit: y is masked for both subsequent selectors; given is not immune to masked names. import x.{given_T as _, given}

@som-snytt som-snytt marked this pull request as ready for review May 30, 2024 01:08
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwsie!

@som-snytt
Copy link
Contributor Author

My previous to-do comment was wrong. given is masked in the usual way. For -Xsource:3, given is subsumed by *, so it would be redundant to retain both selectors (since Scala 2 has implicits but no givens).

@som-snytt som-snytt force-pushed the issue/12999-import-given branch from 38a2b95 to 66e9c39 Compare June 3, 2024 17:15
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Jun 3, 2024
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@lrytz lrytz merged commit 604af3b into scala:2.13.x Jun 4, 2024
@@ -1950,6 +1950,11 @@ trait Contexts { self: Analyzer =>
renamed = true
else if (current.isWildcard && !renamed && !requireExplicit)
result = maybeNonLocalMember(name)
else if (current.isGiven && !requireExplicit) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have the !renamed condition, same as the wildcard case.

import x.{y as z, given} means z should resolve to y not implicit x.z via the given selector.

Copy link
Contributor Author

@som-snytt som-snytt Jun 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this works in Scala 3

scala> object Renamer {
     |   import TX.{f as tInt, given}
     |   def test = implicitly[T[Int]]
     | }

so a rename is not like a mask. That is, x.y as z means y is not available in subsequent wildcard selectors. But it does not mean z is not made available by wildcard selector!

But Scala 2 now: diverging implicit expansion for type T[Int]

@som-snytt som-snytt deleted the issue/12999-import-given branch June 4, 2024 16:58
@SethTisue SethTisue changed the title Import selector can be given Align with Scala 3: Under -Xsource:3, allow importing given, for cross-building Aug 22, 2024
@xuwei-k
Copy link
Contributor

xuwei-k commented Sep 26, 2024

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
Development

Successfully merging this pull request may close these issues.

Import given
5 participants