Skip to content

Commit

Permalink
Appease Scala 2.10 macro gods
Browse files Browse the repository at this point in the history
  • Loading branch information
andyscott committed Sep 3, 2016
1 parent 6bdc2ae commit a5cb3dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
19 changes: 9 additions & 10 deletions core/src/main/scala/cats/arrow/FunctionK.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package arrow

import cats.data.Coproduct

import reflect.macros.blackbox.Context
import cats.macros.MacroCompat

trait FunctionK[F[_], G[_]] extends Serializable { self =>
def apply[A](fa: F[A]): G[A]
Expand Down Expand Up @@ -37,13 +37,12 @@ object FunctionK {

}

object FunctionKMacros {
object FunctionKMacros extends MacroCompat {

def lift[
F[_]: λ[α[_] c.WeakTypeTag[α[_]]],
G[_]: λ[α[_] c.WeakTypeTag[α[_]]]
](c: Context)(
f: c.Expr[F[α] G[α]] forSome { type α }
def lift[F[_], G[_]](c: Context)(
f: c.Expr[(F[α] G[α]) forSome { type α }]
)(
implicit evF: c.WeakTypeTag[F[_]], evG: c.WeakTypeTag[G[_]]
): c.Expr[FunctionK[F, G]] = {
import c.universe._

Expand All @@ -54,7 +53,7 @@ object FunctionKMacros {

def punchHole(tpe: Type): Tree = tpe match {
case PolyType(undet :: Nil, underlying: TypeRef)
val α = TypeName("α")
val α = compatNewTypeName(c, "α")
def rebind(typeRef: TypeRef): Tree =
if (typeRef.sym == undet) tq""
else {
Expand Down Expand Up @@ -82,8 +81,8 @@ object FunctionKMacros {
s"type parameter $param must not be supplied when lifting function $trans to FunctionK")
}

val F = punchHole(weakTypeTag[F[_]].tpe)
val G = punchHole(weakTypeTag[G[_]].tpe)
val F = punchHole(evF.tpe)
val G = punchHole(evG.tpe)

q"""
new FunctionK[$F, $G] {
Expand Down
15 changes: 15 additions & 0 deletions macros/src/main/scala/cats/macros/compat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cats
package macros

/** Macro compatibility.
*
* Used only to push deprecation errors in core off into
* the macros project, as warnings.
*/
private[cats] class MacroCompat {

type Context = reflect.macros.Context
def compatNewTypeName(c: Context, name: String): c.TypeName =
c.universe.newTypeName(name)

}

0 comments on commit a5cb3dc

Please sign in to comment.