From f53b9b8665662a557e48ebd6280f6c5b2ea80804 Mon Sep 17 00:00:00 2001 From: Mateusz Kubuszok Date: Thu, 4 Oct 2018 23:59:28 +0200 Subject: [PATCH] Preparations for Scala 2.13 --- .travis.yml | 3 +- catnip.sbt | 4 +- lock.sbt | 2 +- modules/catnip-tests/.js/lock.sbt | 2 +- modules/catnip-tests/.jvm/lock.sbt | 2 +- .../scala/io/scalaland/catnip/SemiSpec.scala | 16 ++++++-- modules/catnip/.js/lock.sbt | 2 +- modules/catnip/.jvm/lock.sbt | 2 +- .../catnip/internals/DerivedImpl.scala | 15 ++++--- project/Dependencies.scala | 5 +-- project/Settings.scala | 39 ++++++++++++++++--- project/build.properties | 2 +- scripts/sbt | 6 +-- 13 files changed, 66 insertions(+), 34 deletions(-) diff --git a/.travis.yml b/.travis.yml index eac8d05..972bf86 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,7 @@ language: scala scala: - - 2.12.6 + - 2.11.12 + - 2.12.7 jdk: - openjdk8 - oraclejdk8 diff --git a/catnip.sbt b/catnip.sbt index 810fdf2..d9ab1d3 100644 --- a/catnip.sbt +++ b/catnip.sbt @@ -15,7 +15,6 @@ lazy val catnip = crossProject(JVMPlatform, JSPlatform).crossType(CrossType.Pure .setInitialImport("cats.implicits._") .configureModule .publish - .settings(addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross sbt.CrossVersion.patch)) lazy val catnipJVM = catnip.jvm .settings(Compile / unmanagedResourceDirectories += baseDirectory.value / "../src/main/resources") @@ -32,8 +31,7 @@ lazy val catnipTests = crossProject(JVMPlatform, JSPlatform).crossType(CrossType .noPublish .settings(libraryDependencies ++= Seq( "org.specs2" %%% "specs2-core" % Dependencies.specs2Version % "test", - "org.specs2" %%% "specs2-scalacheck" % Dependencies.specs2Version % "test", - compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross sbt.CrossVersion.patch) + "org.specs2" %%% "specs2-scalacheck" % Dependencies.specs2Version % "test" )) lazy val catnipTestsJVM = catnipTests.jvm diff --git a/lock.sbt b/lock.sbt index c790838..ef2d512 100644 --- a/lock.sbt +++ b/lock.sbt @@ -4,4 +4,4 @@ dependencyOverrides ++= Seq( ) -// LIBRARY_DEPENDENCIES_HASH 0c1ecb84eefded81e31012edb83a33973e7edae4 +// LIBRARY_DEPENDENCIES_HASH fdc28634c6c339ea10ce9da391ecaee94ec774d2 diff --git a/modules/catnip-tests/.js/lock.sbt b/modules/catnip-tests/.js/lock.sbt index 9afc22d..ffdba4f 100644 --- a/modules/catnip-tests/.js/lock.sbt +++ b/modules/catnip-tests/.js/lock.sbt @@ -20,4 +20,4 @@ dependencyOverrides ++= Seq( "org.typelevel" % "machinist_sjs0.6_2.12" % "0.6.5", "org.typelevel" % "macro-compat_2.12" % "1.1.1" ) -// LIBRARY_DEPENDENCIES_HASH 53a6369e0770c15ad470d90546a57e0825f8e5a2 +// LIBRARY_DEPENDENCIES_HASH a920cfdde255319e948d05199b843902b066cec3 diff --git a/modules/catnip-tests/.jvm/lock.sbt b/modules/catnip-tests/.jvm/lock.sbt index 3099f8d..12bb0bb 100644 --- a/modules/catnip-tests/.jvm/lock.sbt +++ b/modules/catnip-tests/.jvm/lock.sbt @@ -13,4 +13,4 @@ dependencyOverrides ++= Seq( "org.typelevel" % "machinist_2.12" % "0.6.5", "org.typelevel" % "macro-compat_2.12" % "1.1.1" ) -// LIBRARY_DEPENDENCIES_HASH c17086026af918499dae1c57e5536983dced8f39 +// LIBRARY_DEPENDENCIES_HASH 05d734ce988c78042c9d3924eee3e08f8404af49 diff --git a/modules/catnip-tests/src/test/scala/io/scalaland/catnip/SemiSpec.scala b/modules/catnip-tests/src/test/scala/io/scalaland/catnip/SemiSpec.scala index 8c97444..a30506b 100644 --- a/modules/catnip-tests/src/test/scala/io/scalaland/catnip/SemiSpec.scala +++ b/modules/catnip-tests/src/test/scala/io/scalaland/catnip/SemiSpec.scala @@ -151,9 +151,11 @@ class SemiSpec extends Specification { result1 must not(beEqualTo(result2)) } + @Semi(cats.Functor) final case class TestFunctor[A](a: A, b: A) "generate for cats.Functor" in { // given - @Semi(cats.Functor) final case class TestFunctor[A](a: A, b: A) + // test class moved outside as a workaround for error in 2.11: + // can't existentially abstract over parameterized type TestFunctor[String] // when val result1 = TestFunctor("1", "3").map(_.toInt) @@ -181,9 +183,11 @@ class SemiSpec extends Specification { result2 must beEqualTo(2) } + @Semi(cats.Traverse) final case class TestTraverse[A](a: A) "generate for cats.Traverse" in { // given - @Semi(cats.Traverse) final case class TestTraverse[A](a: A) + // test class moved outside as a workaround for error in 2.11: + // can't existentially abstract over parameterized type TestTraverse[Int] // when val result1 = TestTraverse(Option("1")).sequence @@ -264,9 +268,11 @@ class SemiSpec extends Specification { result2 must beEqualTo(TestSemi("ba")) } + @Semi(cats.SemigroupK, cats.Eq) final case class TestSemiK[A](a: List[A]) "generate for cats.SemigroupK" in { // given - @Semi(cats.SemigroupK, cats.Eq) final case class TestSemiK[A](a: List[A]) + // test class moved outside as a workaround for error in 2.11: + // can't existentially abstract over parameterized type TestSemiK[String] // when implicit val a = cats.SemigroupK[TestSemiK].algebra[String] @@ -278,9 +284,11 @@ class SemiSpec extends Specification { result2 must beEqualTo(TestSemiK(List("b", "a"))) } + @Semi(alleycats.Empty) final case class TestEmpty[A](a: A) "generate for alleycats.Empty" in { // given - @Semi(alleycats.Empty) final case class TestEmpty[A](a: A) + // test class moved outside as a workaround for error in 2.11: + // can't existentially abstract over parameterized type TestEmpty[String] // when val result = alleycats.Empty[TestEmpty[String]].empty diff --git a/modules/catnip/.js/lock.sbt b/modules/catnip/.js/lock.sbt index 7b704ed..84b18c9 100644 --- a/modules/catnip/.js/lock.sbt +++ b/modules/catnip/.js/lock.sbt @@ -20,4 +20,4 @@ dependencyOverrides ++= Seq( "org.typelevel" % "machinist_sjs0.6_2.12" % "0.6.5", "org.typelevel" % "macro-compat_2.12" % "1.1.1" ) -// LIBRARY_DEPENDENCIES_HASH 3c6d978973e31cf767d13efdc069b2682bf4808f +// LIBRARY_DEPENDENCIES_HASH 00c53c6e5d924d4cad98ded5d91dd811f6880dc2 diff --git a/modules/catnip/.jvm/lock.sbt b/modules/catnip/.jvm/lock.sbt index f20e83e..4d472ab 100644 --- a/modules/catnip/.jvm/lock.sbt +++ b/modules/catnip/.jvm/lock.sbt @@ -13,4 +13,4 @@ dependencyOverrides ++= Seq( "org.typelevel" % "machinist_2.12" % "0.6.5", "org.typelevel" % "macro-compat_2.12" % "1.1.1" ) -// LIBRARY_DEPENDENCIES_HASH 034fe611c66be1cd21d62f3d943e26ff345738b7 +// LIBRARY_DEPENDENCIES_HASH 79ffe92df636aa1d6c286e671daf2fe2f4fa8d65 diff --git a/modules/catnip/src/main/scala/io/scalaland/catnip/internals/DerivedImpl.scala b/modules/catnip/src/main/scala/io/scalaland/catnip/internals/DerivedImpl.scala index 3537ecc..0843dea 100644 --- a/modules/catnip/src/main/scala/io/scalaland/catnip/internals/DerivedImpl.scala +++ b/modules/catnip/src/main/scala/io/scalaland/catnip/internals/DerivedImpl.scala @@ -2,7 +2,7 @@ package io.scalaland.catnip.internals import scala.language.experimental.macros import scala.reflect.macros.whitebox.Context -import scala.util.Try +import scala.util.{ Failure, Success, Try } private[catnip] class DerivedImpl(config: Map[String, (String, List[String])])(val c: Context)(annottees: Seq[Any]) extends Loggers { @@ -105,9 +105,8 @@ private[catnip] class DerivedImpl(config: Map[String, (String, List[String])])(v private[catnip] object DerivedImpl { - private def loadConfig(name: String) = + private def loadConfig(name: String): Either[String, Map[String, (String, List[String])]] = Try { - scala.io.Source .fromURL(getClass.getClassLoader.getResources(name).nextElement) .getLines @@ -122,11 +121,11 @@ private[catnip] object DerivedImpl { typeClass.trim -> (generator -> otherRequiredTC) } .toMap - }.toEither.left.map { - case _: java.util.NoSuchElementException => - s"Unable to load $name using ${getClass.getClassLoader}" - case err: Throwable => - err.getMessage + } match { + case Success(value) => Right(value) + case Failure(_: java.util.NoSuchElementException) => + Left(s"Unable to load $name using ${getClass.getClassLoader}") + case Failure(err: Throwable) => Left(err.getMessage) } private val mappingsE: Either[String, Map[String, (String, List[String])]] = loadConfig("derive.semi.conf") diff --git a/project/Dependencies.scala b/project/Dependencies.scala index fd2e6c8..e8222c3 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -9,15 +9,14 @@ object Dependencies { // scala version val scalaOrganization = "org.scala-lang" // "org.typelevel" - val scalaVersion = "2.12.6" // "2.12.4-bin-typelevel-4" - val crossScalaVersions = Seq("2.12.6") + val scalaVersion = "2.12.7" // "2.12.4-bin-typelevel-4" + val crossScalaVersions = Seq("2.11.12", "2.12.7", "2.13.0-M4") // build tools version val scalaFmtVersion = "1.5.1" // libraries versions val catsVersion = "1.3.1" - val monixVersion = "3.0.0-RC1" val specs2Version = "4.3.4" // resolvers diff --git a/project/Settings.scala b/project/Settings.scala index 9109b41..d569528 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -38,6 +38,8 @@ object Settings extends Dependencies { "-language:implicitConversions", "-language:postfixOps", // private options + "-Xexperimental", + "-Ymacro-annotations", "-Yno-adapted-args", "-Ypartial-unification", // warnings @@ -75,6 +77,29 @@ object Settings extends Dependencies { "-Xlint:stars-align", "-Xlint:type-parameter-shadow", "-Xlint:unsound-match" + ).filterNot( + (if (scalaVersion.value.startsWith("2.13")) Set( + // removed in 2.13.x + "-Yno-adapted-args", + "-Ypartial-unification", + // only for 2.11.x + "-Xexperimental" + ) else if (scalaVersion.value.startsWith("2.12")) Set( + // added in 2.13.x + "-Ymacro-annotations", + // only for 2.11.x + "-Xexperimental" + ) else if (scalaVersion.value.startsWith("2.11")) Set( + // added in 2.13.x + "-Ymacro-annotations", + // added in 2.12.x + "-Ywarn-extra-implicit", + "-Ywarn-macros:after", + "-Ywarn-unused:implicits", + "-Ywarn-unused:patvars", + "-Ywarn-unused:privates", + "-Xlint:constant" + ) else Set.empty[String]).contains _ ), console / scalacOptions --= Seq( // warnings @@ -111,10 +136,13 @@ object Settings extends Dependencies { Wart.Nothing, Wart.ToString ) - ) ++ mainDeps + ) ++ mainDeps ++ Seq(libraryDependencies ++= (if (!scalaVersion.value.startsWith("2.13")) { + Seq(compilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross sbt.CrossVersion.patch)) + } else { + Nil + })) private val publishSettings = Seq( - organization := "io.scalaland", homepage := Some(url("https://scalaland.io")), licenses := Seq("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), scmInfo := Some( @@ -132,20 +160,19 @@ object Settings extends Dependencies { pomIncludeRepository := { _ => false }, - pomExtra := ( + pomExtra := krzemin Piotr KrzemiƄski - http://github.com/krzemin + https://github.com/krzemin MateuszKubuszok Mateusz Kubuszok - http://github.com/MateuszKubuszok + https://github.com/MateuszKubuszok - ) ) private val noPublishSettings = diff --git a/project/build.properties b/project/build.properties index 5620cc5..0cd8b07 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.2.1 +sbt.version=1.2.3 diff --git a/scripts/sbt b/scripts/sbt index c46d1f4..ab87207 100755 --- a/scripts/sbt +++ b/scripts/sbt @@ -9,8 +9,8 @@ set -o pipefail declare -r sbt_release_version="0.13.17" declare -r sbt_unreleased_version="0.13.17" -declare -r latest_213="2.13.0-M4" -declare -r latest_212="2.12.6" +declare -r latest_213="2.13.0-M5" +declare -r latest_212="2.12.7" declare -r latest_211="2.11.12" declare -r latest_210="2.10.7" declare -r latest_29="2.9.3" @@ -23,7 +23,7 @@ declare -r sbt_launch_ivy_snapshot_repo="https://repo.scala-sbt.org/scalasbt/ivy declare -r sbt_launch_mvn_release_repo="http://repo.scala-sbt.org/scalasbt/maven-releases" declare -r sbt_launch_mvn_snapshot_repo="http://repo.scala-sbt.org/scalasbt/maven-snapshots" -declare -r default_jvm_opts_common="-Xms512m -Xmx1536m -Xss2m" +declare -r default_jvm_opts_common="-Xms512m -Xss2m" declare -r noshare_opts="-Dsbt.global.base=project/.sbtboot -Dsbt.boot.directory=project/.boot -Dsbt.ivy.home=project/.ivy" declare sbt_jar sbt_dir sbt_create sbt_version sbt_script sbt_new