Skip to content

Commit

Permalink
Remove deprecated ? syntax
Browse files Browse the repository at this point in the history
Scala 2.13.6 and 2.12.14 will interpret `?` as a wildcard when using the
`-Xsource:3` flag (cf scala/scala#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
scala/scala-dev#769).

Sincet this is a breaking change, we also bump the version to
0.12.0-SNAPSHOT.
  • Loading branch information
smarter committed Apr 30, 2021
1 parent 51ffa99 commit bcaeeb3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 50 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -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. `α$`, `β$`, ...

Expand Down
44 changes: 12 additions & 32 deletions src/main/scala/KindProjector.scala
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions src/test/scala-2.13.2+/WarningSuppression.scala

This file was deleted.

14 changes: 5 additions & 9 deletions src/test/scala/test.scala
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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]]]
Expand All @@ -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]]]
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
@@ -1 +1 @@
version in ThisBuild := "0.11.4-SNAPSHOT"
version in ThisBuild := "0.12.0-SNAPSHOT"

0 comments on commit bcaeeb3

Please sign in to comment.