Git Product home page Git Product logo

scala3-migrate's Introduction

scala3-migrate Latest version Build status

Scala 3 migration plugin for sbt

User documentation

The complete documentation of sbt-scala3-migrate can be found in docs.scala-lang.org.

Usage

Requirements

  • sbt 1.5 or higher
  • java 8 or 11
  • scala 2.13, preferred 2.13.14

Installation

// project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.6.2")

Porting the build

To port a build to Scala 3, run the following commands in order, in each project of the build:

  1. migrateDepedendencies <project> helps you update the list of libraryDependencies
  2. migrateScalacOptions <project> helps you update the list of scalacOptions
  3. migrateSyntax <project> fixes a number of syntax incompatibilities between Scala 2.13 and Scala 3
  4. migrateTypes <project> tries to make your code compile with Scala 3 by inferring a few types and resolving a few implicits.

Contributions and feedbacks are welcome

The tool is still under development, and we would love to hear from you. Every feedback will help us build a better tool: typos, clearer log messages, better documentation, bug reports, ideas of features, so please open GitHub issues.

Acknowledgments

This tool is developed by the Scala Center

scala3-migrate's People

Contributors

adpi2 avatar aholland avatar bishabosha avatar busybyte avatar divine-shadow avatar gianick avatar kacperfkorban avatar keyno63 avatar mlachkar avatar plokhotnyuk avatar scala-center-steward[bot] avatar scala-steward avatar sjrd avatar sourcecodebot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scala3-migrate's Issues

SemanticDB not found

Running migrateSyntax plugin errors

[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/PactPluginServiceTest.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/PactPluginServiceTest.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/AvroRecordTest.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/AvroRecordTest.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/TestSchemas.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/TestSchemas.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsArraysTest.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsArraysTest.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsMapsTest.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsMapsTest.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsTest.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/implicits/RecordImplicitsTest.scala.
[error] Failed to fix syntax in src/test/scala/com/github/austek/plugin/avro/utils/MatchingRuleCategoryImplicits.scala because: SemanticDB not found: modules/plugin/src/test/scala/com/github/austek/plugin/avro/utils/MatchingRuleCategoryImplicits.scala

Here is the branch with the problem
https://github.com/austek/pact-avro-plugin/tree/migrate-bug

Publishing migrate-rules as a 2.12 artifact

Hi, thanks for the migration project, it's really useful.

It's my understanding that to run an external rule, you can't use the CLI and instead, you must use the sbt plugin. I've tried different syntax including, for example : scalafix -r dependency:[email protected]:migrate-rules:0.4.2, but none of them work.

So back in sbt I try to do:

sbt> scalafix dependency:[email protected]:migrate-rules:0.4.2
[error] (module1 / Compile / scalafix) scalafix.sbt.InvalidArgument: Failed to fetch [Dependency(Module(ch.epfl.scala, migrate-rules_2.12), 0.4.2)]from [...]

But it fails because it's looking for a 2.12 artifact. I do not have a problem with the migration-plugin itself, running migrate-syntax project works fine. But if I try to use the rules, individually, it fails.

I want to be able to run the rule individually because we have a pipeline to run scalafix for us, on a project, given a rule and open a PR when successful.

migrate-libs -> 2 versions of the same dependency

First of all, thank you so much for this tool! I'll try to use it in a few repositories and give more feedback if I can.

When using migrate-libs I got a suggestion for 2 versions of the same dependency, I guess is an error, see attached image:
imagen

New release for RC2?

I am trying to migrate code from scala 2.13 but scalaz is only now available for RC2.
scala3-migrate is hardcoded to look for RC1 libs at present.

I tried to build from source, and change the plugin to 0.4.0-SNAPSHOT, then publishLocal but sbt does not seem to pick things up.

sbt 1.4.x seems to be required

The readme says that the plugin requires sbt 1.3.x or above, but using 1.3.x yields the following error at load time:

[error] java.lang.NoSuchMethodError: sbt.Def$.ifS(Lsbt/internal/util/Init$Initialize;Lsbt/internal/util/Init$Initialize;Lsbt/internal/util/Init$Initialize;)Lsbt/internal/util/Init$Initialize;

Upgrading to sbt 1.4.x fixes that issue.

The readme should be updated, or we should actually make it work with 1.3.x.

confusion around necessity of adding explicit result types and implicits

https://github.com/scalacenter/scala3-migrate#fix-syntax-incompatibilities does not mention adding result types to anything, but it currently does via ExplicitResultTypes rule
it looks like it should not because adding result types is not necessary to fix syntax
moreover afaik it is only necessary to add result types to implicits to compile with scala3, adding them everywhere is noisy
i guess it would be enough to just remove ExplicitResultTypes usage, since migrate would later invoke InferTypes anyway

and is ExplicitImplicitsRule really necessary?

Be able to specify the configuration name when running migrate commands

Right now only Compile configuration is taken (which means that we retrieve scalacOptions and library dependencies that are specific to Compile config). We would like to extend that to other configs.
Like this:
migrate-... <project> / ConfigName for migrating other configs than thecompile config

Task "migrate-syntax" fails due to colons within path strings on Windows

Task migrate-syntax falls over while trying to normalize Windows paths, apparently by including colons (":") in the path string being normalized.

[IJ]migrate-syntax aholland-scala-utils-scala_3
[success] Total time: 0 s, completed 24 Mar 2021, 12:16:11
[success] Total time: 2 s, completed 24 Mar 2021, 12:16:13
[success] Total time: 2 s, completed 24 Mar 2021, 12:16:15
[info] We are going to fix some syntax incompatibilities on aholland-scala-utils-scala_3
[error]
[error]
[error] Failed fixing the syntax for aholland-scala-utils-scala_3 project
[error] Illegal char <:> at index 88: /home/runner/work/scala3-migrate/scala3-migrate/scalafix/rules/target/scala-2.13/classes:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.5/scala-library-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/epfl/scala/scalafix-core_2.13/0.9.26/scalafix-core_2.13-0.9.26.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/epfl/scala/scalafix-rules_2.13/0.9.26/scalafix-rules_2.13-0.9.26.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalameta_2.13/4.4.10/scalameta_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/googlecode/java-diff-utils/diffutils/1.3.0/diffutils-1.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/geirsson/metaconfig-typesafe-config_2.13/0.9.10/metaconfig-typesafe-config_2.13-0.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.4.1/scala-collection-compat_2.13-2.4.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac-core_2.13.5/4.4.10/semanticdb-scalac-core_2.13.5-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/parsers_2.13/4.4.10/parsers_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scalap/2.13.5/scalap-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/geirsson/metaconfig-core_2.13/0.9.10/metaconfig-core_2.13-0.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/config/1.2.1/config-1.2.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.5/scala-compiler-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/trees_2.13/4.4.10/trees_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/
typelevel/paiges-core_2.13/0.3.0/paiges-core_2.13-0.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/pprint_2.13/0.5.9/pprint_2.13-0.5.9.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.5/scala-reflect-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.19.0/jline-3.19.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/common_2.13/4.4.10/common_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/scalapb-runtime_2.13/0.10.11/scalapb-runtime_2.13-0.10.11.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/fastparse_2.13/1.0.1/fastparse_2.13-1.0.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fansi_2.13/0.2.9/fansi_2.13-0.2.9.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.13/0.2.3/sourcecode_2.13-0.2.3.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/lenses_2.13/0.10.11/lenses_2.13-0.10.11.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.11.4/protobuf-java-3.11.4.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fastparse_2.13/2.3.0/fastparse_2.13-2.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/fastparse-utils_2.13/1.0.1/fastparse-utils_2.13-1.0.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.13/0.6.0/geny_2.13-0.6.0.jar
[error] java.base/sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)
[error] java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:153)
[error] java.base/sun.nio.fs.WindowsPathParser.parse(WindowsPathParser.java:77)
[error] java.base/sun.nio.fs.WindowsPath.parse(WindowsPath.java:92)
[error] java.base/sun.nio.fs.WindowsFileSystem.getPath(WindowsFileSystem.java:229)
[error] java.base/java.nio.file.Path.of(Path.java:147)
[error] java.base/java.nio.file.Paths.get(Paths.java:69)
[error] migrate.internal.AbsolutePath.toNio(AbsolutePath.scala:12)
[error] migrate.internal.AbsolutePath.<init>(AbsolutePath.scala:10)
[error] migrate.internal.AbsolutePath$.apply(AbsolutePath.scala:9)
[error] migrate.internal.AbsolutePath$.$anonfun$from$1(AbsolutePath.scala:25)
[error] scala.util.Try$.apply(Try.scala:210)
[error] migrate.internal.AbsolutePath$.from(AbsolutePath.scala:25)
[error] migrate.internal.Classpath$.$anonfun$from$1(Classpath.scala:24)
[error] scala.collection.immutable.List.map(List.scala:246)
[error] migrate.internal.Classpath$.from(Classpath.scala:24)
[error] migrate.utils.ScalafixService$.internalRules$lzycompute(ScalafixService.scala:70)
[error] migrate.utils.ScalafixService$.internalRules(ScalafixService.scala:70)
[error] migrate.utils.ScalafixService$.$anonfun$from$1(ScalafixService.scala:86)
[error] scala.util.Success.flatMap(Try.scala:258)
[error] migrate.utils.ScalafixService$.from(ScalafixService.scala:85)
[error] migrate.interfaces.MigrateImpl.$anonfun$migrateSyntax$6(MigrateImpl.scala:70)
[error] scala.util.Success.flatMap(Try.scala:258)
[error] migrate.interfaces.MigrateImpl.$anonfun$migrateSyntax$3(MigrateImpl.scala:67)
[error] scala.util.Success.flatMap(Try.scala:258)
[error] migrate.interfaces.MigrateImpl.$anonfun$migrateSyntax$2(MigrateImpl.scala:66)
[error] scala.util.Success.flatMap(Try.scala:258)
[error] migrate.interfaces.MigrateImpl.migrateSyntax(MigrateImpl.scala:65)
[error] migrate.ScalaMigratePlugin$.$anonfun$migrateSyntaxImpl$3(ScalaMigratePlugin.scala:223)
[error] scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] scala.util.Try$.apply(Try.scala:213)
[error] migrate.ScalaMigratePlugin$.$anonfun$migrateSyntaxImpl$1(ScalaMigratePlugin.scala:219)
[error] migrate.ScalaMigratePlugin$.$anonfun$migrateSyntaxImpl$1$adapted(ScalaMigratePlugin.scala:207)
[error] scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:62)
[error] sbt.std.Transform$$anon$4.work(Transform.scala:68)
[error] sbt.Execute.$anonfun$submit$2(Execute.scala:282)
[error] sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:23)
[error] sbt.Execute.work(Execute.scala:291)
[error] sbt.Execute.$anonfun$submit$1(Execute.scala:282)
[error] sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] sbt.CompletionService$$anon$2.call(CompletionService.scala:64)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
[error] java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
[error] java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
[error] java.base/java.lang.Thread.run(Thread.java:832)

Be smarter about scala.js

I get a lot of these:

[info] org.scala-js:scalajs-compiler:1.5.0:plugin->default(compile) -> X : Scala 2 compiler plugins are not supported in scala 3.0.0-RC1. You need to find an alternative
[info] org.scala-js:scalajs-library:1.5.0                           -> "org.scala-js" % "scalajs-library_2.13" % "1.5.0"
[info] org.scala-js:scalajs-test-bridge:1.5.0:test                  -> "org.scala-js" % "scalajs-test-bridge_2.13" % "1.5.0" % "test"

However, these are added via the scalajs sbt plugin, and it's smart enough to not include the compiler plugin on 3.0.0-RC1 (since it's built in) and to add the right versions of its libraries.

So (at least when included via the sbt plugin) these warnings should be silenced. Or at least, they could be printed in a less "scary" way (like more compressed, and with a note saying "you can probably ignore this because ..."

Option to not suggest 2.13 libraries

It is not recommended to publish a library for 3.0 that depends on a library for 2.13, since this can create diamond dependency conflicts. For applications it's fine though.

Either migrate-libs should be configurable to not suggest such changes, or else whenever it suggests a 2.13 replacement it should print the caveat.

fix the revision ordering

//TODO FIX - Wrong revision
  test("wrong revision ordering") {
    Revision("1.0.0-RC21-2")
    Revision("1.0.0")
//   assert(Seq(revision1, revision2) ==  Seq(revision1, revision2).sorted)
  }

Java library being flagged as containing macros

I use SWT in a Scala project and noticed it's getting flagged as containing macros, which I can't imagine is correct considering it's a Java library. I'm not sure what about that library is causing this, but I thought I'd report this because the cause might flag other Java libraries for other people too.

image

scala3-migrate may need a newer scalameta version

When running migrateSyntax, I get the following error:

[error] stack trace is suppressed; run last update for the full output
[error] (update) sbt.librarymanagement.ResolveException: Error downloading org.scalameta:semanticdb-scalac_2.13.13:4.8.8
[error]   Not found
[error]   Not found
[error]   not found: /home/bersier/.ivy2/localorg.scalameta/semanticdb-scalac_2.13.13/4.8.8/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/scalameta/semanticdb-scalac_2.13.13/4.8.8/semanticdb-scalac_2.13.13-4.8.8.pom
[error] Total time: 0 s, completed Mar 6, 2024, 10:46:38 AM
[error] Migration of root failed.

Scala version: 2.13.13
sbt version: 1.9.9

Scala3Compiler fails when scalacOptions enables -Ysemanticdb

The error: CompilationUnit.source is null

[info]   java.lang.NullPointerException:
[info]   at dotty.tools.dotc.semanticdb.ExtractSemanticDB$.absolutePath$1(ExtractSemanticDB.scala:603)
[info]   at dotty.tools.dotc.semanticdb.ExtractSemanticDB$.write(ExtractSemanticDB.scala:606)
[info]   at dotty.tools.dotc.semanticdb.ExtractSemanticDB.run(ExtractSemanticDB.scala:48)
[info]   at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:296)
[info]   at scala.collection.immutable.List.map(List.scala:246)
[info]   at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:297)
[info]   at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
[info]   at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[info]   at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[info]   at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)

When changing CompilationUnit.java with the code below, it doesn't fix the NullPointerException


import dotty.tools.dotc.util.SourceFile;
import scala.io.Codec;
import dotty.tools.dotc.util.SourceFile;
import dotty.tools.io.VirtualFile;
public class CompilationUnit {
  public String content;
  public String name; 
  public CompilationUnit(String name, String content) {
    this.name = name;
    this.content = content;
    this.source = new SourceFile(new VirtualFile(name, content.getBytes()), Codec.UTF8());
  } 
}

Right now, we filter scalac3Options to remove semanticdb

val modified = scala3CompilerOptions.filterNot(_ == "-Ysemanticdb")

Support RC3

sbt:simpleivr> migrate-libs core
[info] 
[info] 
[info] Starting to migrate libDependencies for core
[info] 
[info] X             : Cannot be updated to scala 3
[info] Valid         : Already a valid version for Scala 3
[info] To be updated : Need to be updated to the following version
[info] 
[info] org.typelevel:cats-effect:3.1.0    -> Valid
[info] org.typelevel:cats-free:2.6.0      -> Valid
[info] org.scalatest:scalatest:3.2.8:test -> "org.scalatest" %% "scalatest" % "3.2.7" % "test"
[info] com.lihaoyi:sourcecode:0.2.6       -> "com.lihaoyi" %% "sourcecode" % "0.2.4", "com.lihaoyi" %% "sourcecode" % "0.2.5"

It's rejecting libraries released for RC3 in favor of older versions released for RC2!

Changes not saved to build

Hi! First of all, great work on the tool - I'm sure it'll be greatly appreciated by the community.

I tried migrating a minimal project: https://github.com/kubukoz/daniels-regex-interpreter/tree/bd3da8f3efe6058639df615c87cd74043cbd5b1f - I ran migrate root after adding the sbt plugin and bumping sbt, and there were no changes to files (not even the build.sbt file).

Is that intended, or should the build definition be updated as well and this is a bug?

My setup:

//build.properties
sbt.version=1.5.0-RC2

//project/plugins.sbt
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.3.1")

Original build.sbt file:

ThisBuild / organization := "com.example"
ThisBuild / scalaVersion := "2.13.4"

lazy val root = (project in file(".")).settings(
  name := "ce3.g8",
  libraryDependencies ++= Seq(
    "co.fs2" %% "fs2-core" % "3.0.0-M9"
  )
)

Sources: irrelevant (no changes were required to compile under 3.0.0-RC1)

Output from migrate root:

[success] Total time: 0 s, completed 24 Mar 2021, 17:03:17
[info] compiling 1 Scala source to /Users/jkozlowski/IdeaProjects/daniels-regex-interpreter/target/scala-2.13/classes ...
[success] Total time: 7 s, completed 24 Mar 2021, 17:03:24
[success] Total time: 0 s, completed 24 Mar 2021, 17:03:24
[info] Defining scalaVersion
[info] The new value will be used by Compile / bspBuildTarget, Compile / dependencyTreeCrossProjectId and 56 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] set current project to ce3.g8 (in build file:/Users/jkozlowski/IdeaProjects/daniels-regex-interpreter/)
[success] Total time: 0 s, completed 24 Mar 2021, 17:03:24
[info] We are going to migrate your project root to 3.0.0-RC1
2021.03.24 17:03:27:106 [pool-25...] [INFO ] migrate.Scala3Migrate.previewMigration:29 - Migrating /Users/jkoslowski/IdeaProjects/daniels-regex-interpreter/src/main/scala/com/example/Regular.scala
2021.03.24 17:03:34:921 [pool-25...] [INFO ] migrate.Scala3Migrate.previewMigration:34 - The project compiles successfully in Scala 3
2021.03.24 17:03:34:951 [pool-25...] [INFO ] migrate.Scala3Migrate.compileWithRewrite:109 - Finalizing the migration: compiling in scala 3 with -rewrite option
[info]
[info]
[info] root project has successfully been migrated to scala 3.0.0-RC1
[info] You can now commit the change!
[info] You can also execute the compile command:
[info]
[info] root / compile
[info]
[info]

Note that this did change scalaVersion in the shell, but that wasn't persisted in the files.

Platform: macOS Catalina 10.15.7

NoSuchElementException when running migrateTypes

I'm trying to migrate a project to Scala 3 and am following the migration guide. At the migrateTypes step, I'm running into this error:

[info] Defining scalaVersion
[info] The new value will be used by Compile / bspBuildTarget, Compile / dependencyTreeCrossProjectId and 71 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] set current project to <redacted> (in build file:<redacted>)
[info]
[info] Migrating types in <redacted> / Compile
[info]
bad option '-Ymacro-annotations' was ignored
bad option '-Xsource:3' was ignoredeTypes 1s
missing argument for option -Wunused
  scalac -help  gives more information
[error] Migration of <redacted> / compile failed.
[error] stack trace is suppressed; run last internalMigrateTypes for the full output
[error] (internalMigrateTypes) java.util.NoSuchElementException: None.get
[error] Total time: 3 s, completed 12 Jan 2024, 5:05:32 pm
[info] Defining scalaVersion
[info] The new value will be used by Compile / bspBuildTarget, Compile / dependencyTreeCrossProjectId and 71 others.
[info] 	Run `last` for details.
[info] Reapplying settings...
[info] set current project to <redacted> (in build file:<redacted>)
[error] Migration of <redacted> failed.

So as suggested, I ran the command given:

sbt:<redacted>> last internalMigrateTypes
[error] java.util.NoSuchElementException: None.get
[error] 	at scala.None$.get(Option.scala:627)
[error] 	at scala.None$.get(Option.scala:626)
[error] 	at migrate.compiler.interfaces.Scala3Driver.setup(Scala3Driver.java:22)
[error] 	at migrate.compiler.interfaces.Scala3Driver.setupCompiler(Scala3Driver.java:18)
[error] 	at migrate.compiler.interfaces.Scala3Compiler.setup(Scala3Compiler.java:46)
[error] 	at migrate.Scala3Migrate.$anonfun$setupScala3Compiler$2(Scala3Migrate.scala:89)
[error] 	at scala.util.Try$.apply(Try.scala:210)
[error] 	at migrate.Scala3Migrate.setupScala3Compiler(Scala3Migrate.scala:89)
[error] 	at migrate.Scala3Migrate.migrate(Scala3Migrate.scala:49)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$15(MigrateImpl.scala:54)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$13(MigrateImpl.scala:40)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$12(MigrateImpl.scala:39)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$11(MigrateImpl.scala:38)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$8(MigrateImpl.scala:36)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$5(MigrateImpl.scala:34)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$4(MigrateImpl.scala:33)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.$anonfun$migrate$2(MigrateImpl.scala:32)
[error] 	at scala.util.Success.flatMap(Try.scala:258)
[error] 	at migrate.interfaces.MigrateImpl.migrate(MigrateImpl.scala:31)
[error] 	at migrate.TypeInferenceMigration$.$anonfun$migrateConfig$4(TypeInferenceMigration.scala:51)
[error] 	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23)
[error] 	at scala.util.Try$.apply(Try.scala:213)
[error] 	at migrate.TypeInferenceMigration$.$anonfun$migrateConfig$1(TypeInferenceMigration.scala:40)
[error] 	at migrate.TypeInferenceMigration$.$anonfun$migrateConfig$1$adapted(TypeInferenceMigration.scala:29)
[error] 	at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error] 	at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:63)
[error] 	at sbt.std.Transform$$anon$4.work(Transform.scala:69)
[error] 	at sbt.Execute.$anonfun$submit$2(Execute.scala:283)
[error] 	at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:24)
[error] 	at sbt.Execute.work(Execute.scala:292)
[error] 	at sbt.Execute.$anonfun$submit$1(Execute.scala:283)
[error] 	at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:265)
[error] 	at sbt.CompletionService$$anon$2.call(CompletionService.scala:65)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[error] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[error] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[error] 	at java.base/java.lang.Thread.run(Thread.java:833)
[error] (internalMigrateTypes) java.util.NoSuchElementException: None.get

This is unfortunately not useful to the user.

It turns out, when you look a bit more closely at the output, there is a hint at what is actually the problem:

missing argument for option -Wunused

I removed the option and it works. It would be great if this message is shown in the [error] output instead of the exception.

The version of the plugin I used is 0.6.2.

On Windows, migrate-prepare dies because it uses ':' as classpath separator

sbt:scalajs-jfe> migrate-prepare scalajs-jfe
[success] Total time: 0 s, completed 16 mars 2021 15:00:43
[success] Total time: 0 s, completed 16 mars 2021 15:00:44
[success] Total time: 0 s, completed 16 mars 2021 15:00:44
[info] We are going to fix some syntax incompatibilities on scalajs-jfe
[error]
[error]
[error] Failed fixing the syntax for scalajs-jfe project
[error] Illegal char <:> at index 88: /home/runner/work/scala3-migrate/scala3-migrate/scalafix/rules/target/scala-2.13/classes:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.5/scala-library-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/epfl/scala/scalafix-core_2.13/0.9.26/scalafix-core_2.13-0.9.26.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/ch/epfl/scala/scalafix-rules_2.13/0.9.26/scalafix-rules_2.13-0.9.26.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/scalameta_2.13/4.4.10/scalameta_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/googlecode/java-diff-utils/diffutils/1.3.0/diffutils-1.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/geirsson/metaconfig-typesafe-config_2.13/0.9.10/metaconfig-typesafe-config_2.13-0.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/modules/scala-collection-compat_2.13/2.4.1/scala-collection-compat_2.13-2.4.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/semanticdb-scalac-core_2.13.5/4.4.10/semanticdb-scalac-core_2.13.5-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/parsers_2.13/4.4.10/parsers_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scalap/2.13.5/scalap-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/geirsson/metaconfig-core_2.13/0.9.10/metaconfig-core_2.13-0.9.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/typesafe/config/1.2.1/config-1.2.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.5/scala-compiler-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/trees_2.13/4.4.10/trees_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/typelevel/paiges-core_2.13/0.3.0/paiges-core_2.13-0.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/pprint_2.13/0.5.9/pprint_2.13-0.5.9.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.5/scala-reflect-2.13.5.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/jline/jline/3.19.0/jline-3.19.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/net/java/dev/jna/jna/5.3.1/jna-5.3.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/common_2.13/4.4.10/common_2.13-4.4.10.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/scalapb-runtime_2.13/0.10.11/scalapb-runtime_2.13-0.10.11.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/fastparse_2.13/1.0.1/fastparse_2.13-1.0.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fansi_2.13/0.2.9/fansi_2.13-0.2.9.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/sourcecode_2.13/0.2.3/sourcecode_2.13-0.2.3.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/thesamet/scalapb/lenses_2.13/0.10.11/lenses_2.13-0.10.11.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/google/protobuf/protobuf-java/3.11.4/protobuf-java-3.11.4.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/fastparse_2.13/2.3.0/fastparse_2.13-2.3.0.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scalameta/fastparse-utils_2.13/1.0.1/fastparse-utils_2.13-1.0.1.jar:/home/runner/.cache/coursier/v1/https/repo1.maven.org/maven2/com/lihaoyi/geny_2.13/0.6.0/geny_2.13-0.6.0.jar
[error]
[error]
[success] Total time: 2 s, completed 16 mars 2021 15:00:45

It's also a bit weird that it refers to /home/runner. I was expecting C:\Users\....

Move to 3.0.0-RC3

When I run scala3-migrate it says at the end that I can now upgrade to 3.0.0-RC2, but RC3 is out. Also the library dependency stage for instance suggests moving to _2.13 versions of libraries for which there are RC3 but not RC2 versions. An example being ScalaFX 16.0.0.0-R22 which supports RC3.

[help wanted] asTerm called on not-a-Term val

while migrate PROJECTID it run a while until it ends with

exception caught when loading class Deprecated: java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
[error]
[error]
[error] Migration has failed
[error] because of assertion failed: asTerm called on not-a-Term val

I need help to get the file which cause that Exception.

Migration failed because of null

Hi! I've been following the documentation to migrate a project but I'm running into a problem in the final step. The project consists of a core project which depends on 3 subprojects. I have succesfully migrated the 3 subprojects and executed the migrate-libs/scalacOptions/syntax for the core project. Unfortunately, the migrate step fails with the following error (I've truncated the error trace):

2022.02.15 10:16:04 [INFO] migrate.Scala3Migrate.compileInScala3:133 - Compilation with scala 3 failed.
Please fix the errors above.
[error]
[error] Migration of core / Compile has failed
[error] because of null
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.showArg(Formatting.scala:39)
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.treatArg(Formatting.scala:49)
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.$anonfun$2(Formatting.scala:62)
...
[error] java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error] java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error] java.lang.Thread.run(Thread.java:748)
[error] 
[error] (internalMigrate) 
[error] Migration of core / Compile has failed
[error] because of null
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.showArg(Formatting.scala:39)
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.treatArg(Formatting.scala:49)
[error] dotty.tools.dotc.printing.Formatting$StringFormatter.$anonfun$2(Formatting.scala:62)
...

Possibly related is the following issue: scala/scala3#13440

I'm not sure how to continue the migration, so if you have any ideas on how to proceed that would be greatly appreciated!

Failed to run scalafix with ProcedureSyntax, fix.scala213.ExplicitNullaryEtaExpansion, fix.scala213.ParensAroundLambda, fix.scala213.ExplicitNonNullaryApply, fix.scala213.Any2StringAdd on because missing symbol: jdk.internal.HotSpotIntrinsicCandidate

I am trying to use this tool to port a project to 2.13.11 (with warnings as errors). I have followed the instructions at https://scalacenter.github.io/scala-3-migration-guide/docs/tooling/scala-3-migrate-plugin.html but am running into two errors. If I use jdk18+, I get an error about incompatible class version numbers. If I used jdk 17, I get:
Failed to run scalafix with ProcedureSyntax, fix.scala213.ExplicitNullaryEtaExpansion, fix.scala213.ParensAroundLambda, fix.scala213.ExplicitNonNullaryApply, fix.scala213.Any2StringAdd on /home/lakin/work-repos/playstrategy/lila/modules/tv/src/main/TvTrouper.scala because missing symbol: jdk.internal.HotSpotIntrinsicCandidate

Full log here: https://gist.github.com/lakinwecker/932d5d46c6eaf832777c971892f7bfbf

Unsure if I'm using the wrong jdk version, or if a dependency is using the wrong jdk version. Note that I have only run the migrate-syntax tv command so far.

Modules were resolved with conflicting cross-version suffixes in ProjectRef

First of all, I'd like to thank you for providing this tool for the migration.

I'm trying to migrate a system from Scala 2.13 to Scala 3 with scala3-migrate.

I updated the build.sbt according to the instructions by running migrate-libs projectId . Then I run migrate-libs projectId again, all the libs are valid:
image

But when I try to compile the project, I got this error: Modules were resolved with conflicting cross-version suffixes in ProjectRef:
image

Is this expected? Or should I continue with migrate-scalacOptions, migrate-syntax and migrate, and finally try to compile again?

Environment:

  • sbt: 1.6.2
  • scala: 2.13.8
  • JDK: 11.0.15

Add the crossVersion syntax for migrate-libs

For example when migrate-libs projectId output

[info] ch.epfl.scala:scalafix-rules:0.9.26:test -> "ch.epfl.scala" % "scalafix-rules_2.13" % "0.9.26" % "test"

For sbt >= 1.5.0

      ("ch.epfl.scala"%% "scalafix-rules" % "0.9.26" % Test cross CrossVersion.for3Use2_13)

for sbt > 1.3

      (("ch.epfl.scala"%% "scalafix-rules" % "0.9.26" % Test).withDottyCompat(scalaVersion.value))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.