Scala 2 library TASTy

IMPORTANT

The scala2-library-tasty-experimental is unstable and no library should be published with this as a dependency.

Scala 3 is binary compatible with Scala 2.13. One of the constraints we had to make this work was that we had to use the Scala 2 library (compiled by Scala 2). Therefore we did not have TASTy files for this part of the library.

We want to enhance the Scala 3 experience when using the Scala 2 library without breaking the compatibility. To do so we plan to generate a TASTy-only JAR that contains the TASTy for the Scala 2 library. Both the Scala 2 .class JAR and Scala 3 .tasty JAR will be used as a dependencies. The TASTy is used by the compiler and the .class files are used by the runtime.

Short term goals

  • Allow libraries and tools to test this dependency in their build to help us find issues and stabilize this feature.

Long term goals

  • Improve static analysis tools that require information from the Scala 2 library code.
  • Apply Scala 3 stricter typing rules to Scala 2 library.
  • Use by default when compiling Scala 3 code.

How to use

Supported versions

This library was first published for 3.4.2-RC1-bin-20240311-02c2a6e-NIGHTLY. You will have to use this nightly or a newer one to access this library.

To enable the Scala 2 library TASTy in your project you just need to add the following dependency to your build:


libraryDependencies += "org.scala-lang" %% "scala2-library-tasty-experimental" % scalaVersion.value

A full example is this comment.

What to expect

With this library, the compiler will have a bit more information about the Scala 2 library and will emit a few extra warnings and errors.

Here are some examples of what you can expect:

  • Stricter rules when applying empty parameter lists foo vs. foo().
  • Better detection of pure expressions in statements position.
  • Improved initialization checker analysis.
  • Macros that use reflection might misbehave with this library. Definitions loaded from the Scala 2 library do not have the Scala2x anymore as they are loaded from TASTy. This is an assumption that macro implementations will need to remove.

We tested 1389 projects in the Scala 3 Open Community Build and found 4 projects with errors that need to be fixed in the Scala 2 library or in the user code.

10 Likes