8000 Scalafix rewrite(s) for 2.12->2.13 non-collection library changes · Issue #11430 · scala/bug · GitHub
[go: up one dir, main page]

Skip to content

Scalafix rewrite(s) for 2.12->2.13 non-collection library changes #11430

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

Closed
dwijnand opened this issue Nov 27, 2018 · 7 comments
Closed

Scalafix rewrite(s) for 2.12->2.13 non-collection library changes #11430

dwijnand opened this issue Nov 27, 2018 · 7 comments
Assignees

Comments

@dwijnand
Copy link
Member
dwijnand commented Nov 27, 2018

(Related scala/scala-dev#327 which seems to be about language changes in 2.13)

There are a number of changes in the standard library, to the point I think 2.13 should ship with a Scalafix rewrite for them.

In particular, I'm thinking of scala/scala#5830 (which is a re-submission of scala/scala#5677) which deprecated a number of things and suggests these replacements:

(2019-05-09 edit: No, it didn't. The original PR did, the re-submission just removed the already-deprecated code.)

To compensate for the associated deprecations in your own code:

  • compat.Platform.EOL --> add import java.lang.System.{lineSeparator => EOL}
  • compat.Platform.currentTime --> add import java.lang.System.{currentTimeMillis => currentTime}
  • compat.Platform.arraycopy --> add import java.lang.System.arraycopy
  • sys.error --> throw new RuntimeException (or subclass)
  • sys.exit --> System.exit
  • sys.props --> System.getProperties().asScala (with import scala.collection.JavaConverters._)
  • sys.env --> System.getenv().asScala
  • sys.runtime --> Runtime.getRuntime
  • sys.addShutdownHook --> Runtime.getRuntime.addShutdownHook(new Thread(() => ...))
  • Console.BOLD --> AnsiColor.BOLD (with import scala.io.AnsiColor)
  • Console.readLine --> Console.in.readLine()
  • concurrent.Lock --> java.util.concurrent.locks.ReentrantLock (lock/unlock)

I argue that deprecations in the standard library affect the entire ecosystem, so the release should come with a (or multiple) rewrites. Not because the migration is hard, but because it's so vastly impacting. I would expect it to be much easier than the collection rewrites.

I optimistically target 2.13.0-RC1 🙂

@Jasper-M
Copy link
Jasper-M commented Nov 28, 2018

I seem to have missed/ignored those PRs, but I would like to point out that System.exit is not a direct replacement for sys.exit. The java one has return type Unit, while the Scala one has (the more accurate) return type Nothing.

i.e.

scala> val parsedArg: Int =  util.Try(??? : Int).fold(_ => {println("Usage: ..."); System.exit(1)}, identity)
                                                                                              ^
       error: type mismatch;
        found   : Unit
        required: Int

It's a bit unfortunate that some of these more Scala friendly alternatives would disappear, and then every project needs to factor out the extra boilerplate themselves.

@smarter
8000 Copy link
Member
smarter commented Nov 30, 2018

@Jasper-M Looks like this isn't actually deprecated currently: https://github.com/scala/scala/blob/2.13.x/src/library/scala/sys/package.scala I also agree some of those are worth keeping around.

@adriaanm adriaanm transferred this issue from scala/scala-dev Mar 13, 2019
@adriaanm adriaanm added this to the 2.13.0-RC1 milestone Mar 13, 2019
@SethTisue SethTisue modified the milestones: 2.13.0-RC1, 2.13.0 Apr 3, 2019
@dwijnand dwijnand self-assigned this May 1, 2019
@dwijnand
Copy link
Member Author
dwijnand commented May 1, 2019

I've implemented these in https://github.com/dwijnand/scala-rewrites.

@olafurpg any chance I could get you (and/or anyone else with Scalafix expertise) to review it?

If the Scala maintainers like it I was thinking I could transfer the repo to the scala org so it can be an official part of the 2.13.0 release.

@olafurpg
Copy link
olafurpg commented May 2, 2019

@dwijnand I'm happy to review, where is the best place to leave comments?

For example, matching against Term.Select below
https://github.com/dwijnand/scala-rewrites/blob/ab9e425e4499fc13d3b3451ce6393c05e3541f08/rewrites/src/main/scala/fix/Scala_2_13.scala#L141
will make the rewrite do nothing when colors are referenced as plain identifiers BLACK from a wildcard import Console._.

@dwijnand
Copy link
Member Author
dwijnand commented May 2, 2019

@olafurpg 1-n issues and/or 1-n PRs to the repo, if that works for you.

Good point about Term.Name. I handle that for EOL, but not everywhere. I'll do that.

@dwijnand
Copy link
Member Author
dwijnand commented May 9, 2019

Updated the ticket: The PR that landed didn't add all those deprecations. The original PR did, but the re-submission just removed the already-deprecated code.

I'm continuing to progress in the scala-rewrites repo.

@dwijnand
Copy link
Member Author

Closing in favour of progress being made and tracked in https://github.com/scala/scala-rewrites.

@SethTisue SethTisue removed this from the 2.13.0 milestone May 15, 2019
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

No branches or pull requests

6 participants
0