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

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

Open
dwijnand opened this Issue Nov 27, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@dwijnand
Copy link
Member

dwijnand commented Nov 27, 2018

(Related #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:

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

This comment has been minimized.

Copy link
Member

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

This comment has been minimized.

Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.