diff --git a/.github/workflows/scala.yml b/.github/workflows/scala.yml index ec9fc7c7..6abcf88b 100644 --- a/.github/workflows/scala.yml +++ b/.github/workflows/scala.yml @@ -13,8 +13,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest] - # FIXME Use stable scala version - scala: [2.13.12, 3.3.0] + scala: [2.12.19, 2.13.12, 3.3.0] steps: - uses: actions/checkout@v3 diff --git a/.gitignore b/.gitignore index b20139f0..bd23e50d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ /test-output /project/target /project/project +metals.sbt .cache .history .lib @@ -25,5 +26,6 @@ gpg.sbt modules/**/target */jmh-result.json +.vscode .metals .bloop diff --git a/build.sbt b/build.sbt index 1b87c778..7225937f 100644 --- a/build.sbt +++ b/build.sbt @@ -1,3 +1,4 @@ +lazy val scala212 = "2.12.19" lazy val scala213 = "2.13.12" /* FIXME Return to use a stable version when 'scala.quoted.Quotes.reflectModuleSymbol.newClass' @@ -66,7 +67,7 @@ def crossScalaSettings = { } Seq( - crossScalaVersions := Seq(scala213, scala3), + crossScalaVersions := Seq(scala212, scala213, scala3), Compile / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/main").value, Test / unmanagedSourceDirectories ++= addDirsByScalaVersion("src/test").value ) @@ -89,12 +90,10 @@ lazy val tethys = project.in(file(".")) lazy val modules = file("modules") -def addScalaCompiler(scalaVersion: String): Seq[ModuleID] = +def addScalaReflect(scalaVersion: String): Seq[ModuleID] = CrossVersion.partialVersion(scalaVersion) match { - case Some((2, y)) if y >= 13 => - Seq("org.scala-lang" % "scala-compiler" % scalaVersion % Provided) - case Some((3, _)) => - Seq("org.scala-lang" %% "scala3-compiler" % scalaVersion % Provided) + case Some((2, y)) => + Seq("org.scala-lang" % "scala-reflect" % scalaVersion) case _ => Seq.empty } @@ -104,7 +103,7 @@ lazy val core = project.in(modules / "core") .settings(testSettings) .settings( name := "tethys-core", - libraryDependencies ++= addScalaCompiler(scalaVersion.value) + libraryDependencies ++= addScalaReflect(scalaVersion.value) ) lazy val `macro-derivation` = project.in(modules / "macro-derivation") @@ -113,7 +112,7 @@ lazy val `macro-derivation` = project.in(modules / "macro-derivation") .settings(testSettings) .settings( name := "tethys-derivation", - libraryDependencies ++= addScalaCompiler(scalaVersion.value) + libraryDependencies ++= addScalaReflect(scalaVersion.value) ) .dependsOn(core) diff --git a/modules/core/src/main/scala-2.12/tethys/compat/CollectionBuilder.scala b/modules/core/src/main/scala-2.12/tethys/compat/CollectionBuilder.scala new file mode 100644 index 00000000..0cdc7901 --- /dev/null +++ b/modules/core/src/main/scala-2.12/tethys/compat/CollectionBuilder.scala @@ -0,0 +1,20 @@ +package tethys.compat + +import scala.collection.generic.CanBuildFrom +import scala.collection.mutable +import scala.language.higherKinds + +trait CollectionBuilder[A, C] { + def newBuilder: mutable.Builder[A, C] +} + +object CollectionBuilder { + implicit def seqCBFBuilder[A, C[_]](implicit cbf: CanBuildFrom[Nothing, A, C[A]]): CollectionBuilder[A, C[A]] = new CollectionBuilder[A, C[A]] { + override def newBuilder: mutable.Builder[A, C[A]] = cbf() + } + + implicit def mapCBFBuilder[K, V, M[_, _]](implicit cbf: CanBuildFrom[Nothing, (K, V), M[K, V]]): CollectionBuilder[(K, V), M[K, V]] = + new CollectionBuilder[(K, V), M[K, V]] { + override def newBuilder: mutable.Builder[(K, V), M[K, V]] = cbf() + } +} \ No newline at end of file diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/AutoDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/AutoDerivation.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/AutoDerivation.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/AutoDerivation.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/SemiautoDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/SemiautoDerivation.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/SemiautoDerivation.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/SemiautoDerivation.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/DependentField.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/DependentField.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/DependentField.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/DependentField.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/FieldStyle.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/FieldStyle.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/FieldStyle.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/FieldStyle.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/NotDescribedException.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/NotDescribedException.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/NotDescribedException.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/NotDescribedException.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderBuilder.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderBuilder.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderBuilder.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderBuilder.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderDescription.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderDescription.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderDescription.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderDescription.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderField.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderField.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/ReaderField.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/ReaderField.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/WriterBuilder.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/WriterBuilder.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/WriterBuilder.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/WriterBuilder.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/WriterDescription.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/WriterDescription.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/builder/WriterDescription.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/builder/WriterDescription.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/BaseMacroDefinitions.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/BaseMacroDefinitions.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/BaseMacroDefinitions.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/BaseMacroDefinitions.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/CaseClassUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/CaseClassUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/CaseClassUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/CaseClassUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/LoggingUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/LoggingUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/LoggingUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/LoggingUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/MacroLogging.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/MacroLogging.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/MacroLogging.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/MacroLogging.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/MacroUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/MacroUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/MacroUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/MacroUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderBuilderUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderBuilderUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderBuilderUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderBuilderUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderDescriptionCommons.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderDescriptionCommons.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderDescriptionCommons.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderDescriptionCommons.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderDescriptionMacro.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderDescriptionMacro.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/ReaderDescriptionMacro.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/ReaderDescriptionMacro.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriteBuilderUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriteBuilderUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriteBuilderUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriteBuilderUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriterBuilderCommons.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriterBuilderCommons.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriterBuilderCommons.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriterBuilderCommons.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriterDescriptorMacro.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriterDescriptorMacro.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/builder/WriterDescriptorMacro.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/builder/WriterDescriptorMacro.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/AutoDerivationMacro.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/AutoDerivationMacro.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/AutoDerivationMacro.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/AutoDerivationMacro.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/DerivationUtils.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/DerivationUtils.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/DerivationUtils.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/DerivationUtils.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/ReaderDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/ReaderDerivation.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/ReaderDerivation.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/SemiautoDerivationMacro.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/SemiautoDerivationMacro.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/SemiautoDerivationMacro.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/SemiautoDerivationMacro.scala diff --git a/modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/WriterDerivation.scala b/modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/WriterDerivation.scala similarity index 100% rename from modules/macro-derivation/src/main/scala-2.13+/tethys/derivation/impl/derivation/WriterDerivation.scala rename to modules/macro-derivation/src/main/scala-2/tethys/derivation/impl/derivation/WriterDerivation.scala