From bcaeeb36b07d20873f7516f4c1c65422863ae3ff Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 30 Apr 2021 13:10:37 +0200 Subject: [PATCH] Remove deprecated `?` syntax Scala 2.13.6 and 2.12.14 will interpret `?` as a wildcard when using the `-Xsource:3` flag (cf https://github.com/scala/scala/pull/9560)). This means that the old kind-projector syntax will no longer work, so it seems like a good time to remove it. This will also allow us to compile more of the community-build with `-Xsource:3` enabled (cf https://github.com/scala/scala-dev/issues/769). Sincet this is a breaking change, we also bump the version to 0.12.0-SNAPSHOT. --- README.md | 1 - src/main/scala/KindProjector.scala | 44 +++++-------------- .../scala-2.13.2+/WarningSuppression.scala | 7 --- src/test/scala/test.scala | 14 +++--- version.sbt | 2 +- 5 files changed, 18 insertions(+), 50 deletions(-) delete mode 100644 src/test/scala-2.13.2+/WarningSuppression.scala diff --git a/README.md b/README.md index b6bb0f6..4fd091b 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,6 @@ avoid defining the following identifiers: 1. `Lambda` and `λ` 2. `*`, `+*`, and `-*` - 3. `?`, `+?`, and `-?` ([deprecated syntax](https://github.com/typelevel/kind-projector/issues/108); same meaning as the above) 4. `Λ$` 5. `α$`, `β$`, ... diff --git a/src/main/scala/KindProjector.scala b/src/main/scala/KindProjector.scala index 21ba063..b0ea954 100644 --- a/src/main/scala/KindProjector.scala +++ b/src/main/scala/KindProjector.scala @@ -51,34 +51,19 @@ class KindRewriter(plugin: Plugin, val global: Global) // Reserve some names val TypeLambda1 = newTypeName("Lambda") val TypeLambda2 = newTypeName("λ") - object InvPlaceholder { - def unapply(name: TypeName): Boolean = name == newTypeName("$qmark") || name == newTypeName("$times") - } - object CoPlaceholder { - def unapply(name: TypeName): Boolean = name == newTypeName("$plus$qmark") || name == newTypeName("$plus$times") - } - object ContraPlaceholder { - def unapply(name: TypeName): Boolean = name == newTypeName("$minus$qmark") || name == newTypeName("$minus$times") - } + val InvPlaceholder = newTypeName("$times") + val CoPlaceholder = newTypeName("$plus$times") + val ContraPlaceholder = newTypeName("$minus$times") - def deprecationFor(name: TypeName): Option[(String, String)] = - if (name == newTypeName("$qmark")) Some("?" -> "*") - else if (name == newTypeName("$plus$qmark")) Some("+?" -> "+*") - else if (name == newTypeName("$minus$qmark")) Some("-?" -> "-*") - else None - val TermLambda1 = TypeLambda1.toTermName val TermLambda2 = TypeLambda2.toTermName - class Placeholder(deprecationReporter: (String, String) => Unit) { - def unapply(name: TypeName): Option[Variance] = { - for ((used, preferred) <- deprecationFor(name)) deprecationReporter(used, preferred) - name match { - case InvPlaceholder() => Some(Invariant) - case CoPlaceholder() => Some(Covariant) - case ContraPlaceholder() => Some(Contravariant) - case _ => None - } + object Placeholder { + def unapply(name: TypeName): Option[Variance] = name match { + case InvPlaceholder => Some(Invariant) + case CoPlaceholder => Some(Covariant) + case ContraPlaceholder => Some(Contravariant) + case _ => None } } @@ -255,17 +240,12 @@ class KindRewriter(plugin: Plugin, val global: Global) def handlePlaceholders(t: Tree, as: List[Tree]) = { // create a new type argument list, catching placeholders and create // individual identifiers for them. - val placeholder = new Placeholder((deprecatedName, preferredName) => { - val msg = "kind-projector ? placeholders are deprecated." + - s" Use $preferredName instead of $deprecatedName for cross-compatibility with Scala 3" - global.runReporting.warning(t.pos, msg, Reporting.WarningCategory.Deprecation, t.symbol) - }) val xyz = as.zipWithIndex.map { - case (id @ Ident(placeholder(variance)), i) => + case (Ident(Placeholder(variance)), i) => (Ident(newParamName(i)), Some(Right(variance))) - case (apl @ AppliedTypeTree(Ident(placeholder(variance)), ps), i) => + case (AppliedTypeTree(Ident(Placeholder(variance)), ps), i) => (Ident(newParamName(i)), Some(Left((variance, ps.map(makeComplexTypeParam))))) - case (xst @ ExistentialTypeTree(AppliedTypeTree(Ident(placeholder(variance)), ps), _), i) => + case (ExistentialTypeTree(AppliedTypeTree(Ident(Placeholder(variance)), ps), _), i) => (Ident(newParamName(i)), Some(Left((variance, ps.map(makeComplexTypeParam))))) case (a, i) => (super.transform(a), None) diff --git a/src/test/scala-2.13.2+/WarningSuppression.scala b/src/test/scala-2.13.2+/WarningSuppression.scala deleted file mode 100644 index f50c91e..0000000 --- a/src/test/scala-2.13.2+/WarningSuppression.scala +++ /dev/null @@ -1,7 +0,0 @@ -//don't actually run anything, just demonstrate this compiles with fatal warnings -object Example { - def bar[T[_]] = () - - @scala.annotation.nowarn("cat=deprecation") - def f() = bar[Either[Int, ?]] -} \ No newline at end of file diff --git a/src/test/scala/test.scala b/src/test/scala/test.scala index a975b63..964bc18 100644 --- a/src/test/scala/test.scala +++ b/src/test/scala/test.scala @@ -14,8 +14,8 @@ object Test { baz[({type L[X,Y] = Tuple3[Int, X, Y]})#L] // used to test the plugin - bar[Either[Int, ?]] - baz[Tuple3[Int, ?, ?]] + bar[Either[Int, *]] + baz[Tuple3[Int, *, *]] baz[Tuple3[*, Int, *]] // should not be changed by the plugin @@ -41,8 +41,7 @@ object Test { trait Functor[F[_]] trait EitherT[F[_], A, B] - qux[Functor[?[_]]] - qux[EitherT[?[_], Int, Double]] + qux[Functor[*[_]]] qux[EitherT[*[_], Int, Double]] // higher higher order @@ -54,7 +53,7 @@ object Test { vex[Lambda[A[B[C]] => Unit]] trait FunctorK[F[_[_]]] - vex[FunctorK[?[_[_]]]] + vex[FunctorK[*[_[_]]]] def hex[T[_[_[_[_]]]]] = () hex[({type L[A[_[_[_]]]] = Unit})#L] @@ -63,14 +62,13 @@ object Test { // covariant def mux[T[+_]] = () mux[({type L[+A] = Either[A, Int]})#L] - mux[Either[+?, Int]] + mux[Either[+*, Int]] mux[Lambda[`+A` => Either[A, Int]]] mux[Lambda[+[A] => Either[A, Int]]] // contravariant def bux[T[-_, +_]] = () bux[({type L[-A, +B] = Function2[A, Int, B]})#L] - bux[Function2[-?, Int, +?]] bux[Function2[-*, Int, +*]] bux[Lambda[(`-A`, `+B`) => Function2[A, Int, B]]] bux[Lambda[(-[A], +[B]) => Function2[A, Int, B]]] @@ -79,9 +77,7 @@ object Test { trait ~>[-F[_], +G[_]] def tux[T[-F[_]]] = () def hux[T[+G[_]]] = () - tux[~>[-?[_], Option]] tux[~>[-*[_], Option]] - hux[~>[Option, +?[_]]] hux[~>[Option, +*[_]]] tux[Lambda[`-F[_]` => ~>[F, Option]]] hux[Lambda[`+G[_]` => ~>[Option, G]]] diff --git a/version.sbt b/version.sbt index 7e8d011..12dd689 100644 --- a/version.sbt +++ b/version.sbt @@ -1 +1 @@ -version in ThisBuild := "0.11.4-SNAPSHOT" +version in ThisBuild := "0.12.0-SNAPSHOT"