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

Scala 2 compat: enable reflectiveSelectable for language.reflectiveCalls. #9420

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jul 23, 2020

In Scala 2, calls to structural types that require reflective calls must be enabled with

  import scala.language.reflectiveCalls

In Scala 3, that import has no effect, and reflective calls refuse to compile without the following import:

  import scala.reflect.Selectable.reflectiveSelectable

However, since that import does not compile in Scala 2, there is no way to write code that cross-compiles between Scala 2 and Scala 3 and uses reflective calls to members of structural types.

In this commit, we conditionally enable reflectiveSelectable if a given scala.language.reflectiveCalls is in scope. This straightforwardly allows code to cross-compile by using the Scala 2 language import, without any compiler intervention.

@sjrd sjrd requested a review from odersky July 23, 2020 12:10
Copy link
Member

@dottybot dottybot left a comment

Choose a reason for hiding this comment

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

Hello, and thank you for opening this PR! 🎉

All contributors have signed the CLA, thank you! ❤️

Commit Messages

We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).

Please stick to these guidelines for commit messages:

  1. Separate subject from body with a blank line
  2. When fixing an issue, start your commit message with Fix #<ISSUE-NBR>:
  3. Limit the subject line to 72 characters
  4. Capitalize the subject line
  5. Do not end the subject line with a period
  6. Use the imperative mood in the subject line ("Add" instead of "Added")
  7. Wrap the body at 80 characters
  8. Use the body to explain what and why vs. how

adapted from https://chris.beams.io/posts/git-commit

Have an awesome day! ☀️

…lls.

In Scala 2, calls to structural types that require reflective calls
must be enabled with

  import scala.language.reflectiveCalls

In Scala 3, that import has no effect, and reflective calls refuse
to compile without the following import:

  import scala.reflect.Selectable.reflectiveSelectable

However, since that import does not compile in Scala 2, there is no
way to write code that cross-compiles between Scala 2 and Scala 3
and uses reflective calls to members of structural types.

In this commit, we conditionally enable `reflectiveSelectable` if a
given `scala.language.reflectiveCalls` is in scope. This
straightforwardly allows code to cross-compile by using the Scala 2
language import, without any compiler intervention.
@sjrd sjrd force-pushed the enable-reflective-selectable-for-scala2-language-import branch from b4040da to 0c159c8 Compare July 23, 2020 14:40
@sjrd sjrd assigned odersky and unassigned sjrd Jul 24, 2020
@odersky odersky merged commit 44f13ef into scala:master Jul 27, 2020
@sjrd sjrd deleted the enable-reflective-selectable-for-scala2-language-import branch July 27, 2020 08:13
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.

3 participants