Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated ? syntax #186

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.11.4-SNAPSHOT"
version in ThisBuild := "0.12.0-SNAPSHOT"