-
Notifications
You must be signed in to change notification settings - Fork 1.1k
cross-building with source:3.0-migration compiler option #16720
-
I'm cross-building a library with scala 2.12 and 2.13 and wanted to add support for scala 3.2.1
I added the -source:3.0-migration
scalac option for scala 3, hoping to get some warnings from the compiler on the shared code.
However, this setup does not work if my module contains a specific scala-3
source folder.
if for instance I have in src/main/scala-3/example/Test.scala
package example trait Test: def greet: Unit = println("Hello")
The compiler will not accept the new syntax and prints
[error] -- Error: /path/src/main/scala-3/example/Test.scala:4:2
[error] 4 | def greet: Unit =
[error] | ^^^
[error] | indented definitions expected, def found
Shouldn't the compiler consider scala-3
source folder as already migrated ?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
I'm afraid that the scalac option is applied to the whole compilation classpath by sbt. In the compiler, we don't differentiate directories based on their name (like the scala-3
directory here, which sbt uses to filter the compilation classpath based on the used scala version). Moreover, it is not possible to apply an option to only a part of compilation classpath. Best idea I have for this case is to temporarily split the codebase into separate modules:
- one with only the files in
scala-3
directory, which does not use the "-source:3.0-migration" option - one with all of the other cross-compiled files, which uses the "-source:3.0-migration"
This could be problematic, since the (2.) would have to depend on (1.) (or vice versa), which may not always be possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1