Skip to content

Commit

Permalink
avoid deprecated macro APIs post 2.10 (#2534)
Browse files Browse the repository at this point in the history
* fix hygiene problem in FunctionK

* avoid publishLocal to run bincompat tests

* avoid deprecated macro APIs post 2.10

* removed the publishLocal
  • Loading branch information
larsrh authored and kailuowang committed Sep 28, 2018
1 parent 4acdbb9 commit 957da66
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 26 deletions.
11 changes: 7 additions & 4 deletions binCompatTest/src/main/scala/catsBC/MimaExceptions.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package catsBC
import cats.implicits._
import cats._, data._, cats.arrow._

object MimaExceptions {
import cats.implicits._

def headOption[A](list: List[A]): Option[A] = list.headOption

import cats.arrow.FunctionK // needs to be imported because of a hygiene problem

def isBinaryCompatible = (
Monad[OptionT[List, ?]],
cats.Monad[cats.data.OptionT[List, ?]],
cats.data.OptionT.catsDataTraverseForOptionT[List],
cats.data.Kleisli.catsDataCommutativeArrowForKleisliId,
cats.data.OptionT.catsDataMonoidKForOptionT[List],
Expand All @@ -15,7 +17,8 @@ object MimaExceptions {
cats.data.Kleisli.catsDataCommutativeArrowForKleisli[Option],
cats.data.Kleisli.catsDataCommutativeFlatMapForKleisli[Option, Int],
cats.data.IRWST.catsDataStrongForIRWST[List, Int, Int, Int],
cats.data.OptionT.catsDataMonadErrorMonadForOptionT[List]
cats.data.OptionT.catsDataMonadErrorMonadForOptionT[List],
FunctionK.lift(headOption)
)

}
10 changes: 8 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ def mimaSettings(moduleName: String) = {
exclude[DirectMissingMethodProblem]("cats.data.KleisliInstances4.catsDataCommutativeFlatMapForKleisli"),
exclude[DirectMissingMethodProblem]("cats.data.IRWSTInstances1.catsDataStrongForIRWST"),
exclude[DirectMissingMethodProblem]("cats.data.OptionTInstances1.catsDataMonadErrorMonadForOptionT")
) ++ // Only compile-time abstractions (macros) allowed here
Seq(
exclude[IncompatibleMethTypeProblem]("cats.arrow.FunctionKMacros.lift"),
exclude[MissingTypesProblem]("cats.arrow.FunctionKMacros$"),
exclude[IncompatibleMethTypeProblem]("cats.arrow.FunctionKMacros#Lifter.this"),
exclude[IncompatibleResultTypeProblem]("cats.arrow.FunctionKMacros#Lifter.c")
)
}
)
Expand Down Expand Up @@ -516,10 +522,10 @@ lazy val binCompatTest = project
else //We are not testing BC on Scala 2.13 yet.
"org.typelevel" %% "cats-core" % version.value % Provided
},
"org.typelevel" %% "cats-core" % version.value % Test,
"org.scalatest" %%% "scalatest" % scalatestVersion(scalaVersion.value) % Test
)
)
.dependsOn(coreJVM % Test)


// cats-js is JS-only
Expand Down Expand Up @@ -639,7 +645,7 @@ addCommandAlias("buildAlleycatsJVM", ";alleycatsCoreJVM/test;alleycatsLawsJVM/te

addCommandAlias("buildJVM", ";buildKernelJVM;buildCoreJVM;buildTestsJVM;buildFreeJVM;buildAlleycatsJVM")

addCommandAlias("validateBC", ";catsJVM/publishLocal;binCompatTest/test;mimaReportBinaryIssues")
addCommandAlias("validateBC", ";binCompatTest/test;mimaReportBinaryIssues")

addCommandAlias("validateJVM", ";scalastyle;buildJVM;bench/test;validateBC;makeMicrosite")

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/scala/cats/arrow/FunctionK.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package cats
package arrow

import cats.data.{EitherK, Tuple2K}
import scala.reflect.macros.blackbox.Context

import cats.macros.MacroCompat
import cats.data.{EitherK, Tuple2K}

/**
* `FunctionK[F[_], G[_]]` is a functor transformation from `F` to `G`
Expand Down Expand Up @@ -95,7 +95,7 @@ object FunctionK {

}

private[arrow] object FunctionKMacros extends MacroCompat {
private[arrow] object FunctionKMacros {

def lift[F[_], G[_]](c: Context)(
f: c.Expr[(F[α] G[α]) forSome { type α }]
Expand Down Expand Up @@ -124,7 +124,7 @@ private[arrow] object FunctionKMacros extends MacroCompat {
val G = punchHole(evG.tpe)

q"""
new FunctionK[$F, $G] {
new _root_.cats.arrow.FunctionK[$F, $G] {
def apply[A](fa: $F[A]): $G[A] = $trans(fa)
}
"""
Expand All @@ -139,7 +139,7 @@ private[arrow] object FunctionKMacros extends MacroCompat {

private[this] def punchHole(tpe: Type): Tree = tpe match {
case PolyType(undet :: Nil, underlying: TypeRef)
val α = compatNewTypeName(c, "α")
val α = TypeName("α")
def rebind(typeRef: TypeRef): Tree =
if (typeRef.sym == undet) tq""
else {
Expand Down
15 changes: 0 additions & 15 deletions macros/src/main/scala/cats/macros/compat.scala

This file was deleted.

9 changes: 9 additions & 0 deletions tests/src/test/scala/cats/tests/FunctionKSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ class FunctionKSuite extends CatsSuite {
}
}

test("hygiene") {
trait FunctionK
def optionToList[A](option: Option[A]): List[A] = option.toList
val fOptionToList = cats.arrow.FunctionK.lift(optionToList _)
forAll { (a: Option[Int]) =>
fOptionToList(a) should === (optionToList(a))
}
}

test("lift compound unary") {
val fNelFromList = FunctionK.lift[List, λ[α Option[NonEmptyList[α]]]](NonEmptyList.fromList _)
forAll { (a: List[String]) =>
Expand Down

0 comments on commit 957da66

Please sign in to comment.