bug icon indicating copy to clipboard operation
bug copied to clipboard

Certain type aliases written in Scala 3 can't be used in Scala 2

Open jadenPete opened this issue 4 months ago • 3 comments

Reproduction steps

Scala 2 version: 2.13.16 Scala 3 version: 3.6.3

  1. Clone this minimum reproducability case repository: https://github.com/jadenPete/scala-missing-from-classpath-bug-reproduction

  2. Run sbt compile

  3. Observe the following error:

[error] .../scala-missing-from-classpath-bug-reproduction/program/src/main/scala/Main.scala:8:18: Symbol 'type com.example.package.AnimalList' is missing from the classpath.
[error] This symbol is required by 'object com.example.Person'.
[error] Make sure that type AnimalList is in your classpath and check for conflicting dependencies with `-Ylog-classpath`.
[error] A full rebuild may help if 'Person.class' was compiled against an incompatible version of com.example.package.
[error]     val mickey = Person(pets = List(goofy))
[error]                  ^
[error] one error found

Problem

Certain type aliases written in Scala 3 can't be transitively used by other Scala 2 targets (i.e. referenced in a Scala 2 target that, in turn, is depended on by another Scala 2 target). I'm not sure if this is specific to package objects, but something gets lost in translation when those Scala 3 type aliases are encoded in Scala 2's Pickle format instead of decoded directly from TASTy.

jadenPete avatar Aug 11 '25 15:08 jadenPete

@jadenPete curious, what is your use case for that direction of Scala 3/2 interop / tasty reader?

lrytz avatar Aug 12 '25 11:08 lrytz

We’re migrating our mostly Scala 2 monorepo to Scala 3. The build target with the type aliases was originally written in Scala 2. Unfortunately, it’s not feasible to immediately migrate everything that depends on it to Scala 3 because thousands of build targets to use it.

I should also note that we’ve tried migrating targets at the top of the dependency graph first, but that usually yields way more compiler errors than starting at the bottom.

jadenPete avatar Aug 12 '25 11:08 jadenPete

We should at least evaluate this for 2.13.17. cc @bishabosha

SethTisue avatar Aug 19 '25 09:08 SethTisue