Skip to content

Commit

Permalink
add macro-compat to fix for scala 2.10.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yilinwei committed May 16, 2017
1 parent 946e86a commit c0d8f24
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ lazy val catsJS = project.in(file(".catsJS"))
lazy val macros = crossProject.crossType(CrossType.Pure)
.settings(moduleName := "cats-macros", name := "Cats macros")
.settings(catsSettings:_*)
.settings(scalaMacroDependencies:_*)
.jsSettings(commonJsSettings:_*)
.jvmSettings(commonJvmSettings:_*)
.jsSettings(coverageEnabled := false)
Expand Down Expand Up @@ -448,7 +449,10 @@ lazy val crossVersionSharedSources: Seq[Setting[_]] =
}

lazy val scalaMacroDependencies: Seq[Setting[_]] = Seq(
libraryDependencies += scalaOrganization.value %%% "scala-reflect" % scalaVersion.value % "provided",
libraryDependencies ++= Seq(
scalaOrganization.value % "scala-reflect" % scalaVersion.value % "provided",
scalaOrganization.value % "scala-compiler" % scalaVersion.value % "provided"
),
libraryDependencies ++= {
CrossVersion.partialVersion(scalaVersion.value) match {
// if scala 2.11+ is used, quasiquotes are merged into scala-reflect
Expand Down
17 changes: 11 additions & 6 deletions macros/src/main/scala/cats/macros/canResolve.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package cats
package macros

import reflect.macros.Context
import reflect.macros.blackbox

import macrocompat.bundle

trait ImplicitResolutionSpec {
def canResolve[A, F[_]](imports: Unit): F[A] = macro CanResolveMacro.mkImplicitlyBlock[A, F]
Expand All @@ -19,7 +21,8 @@ object CanResolveMacro {

import CanResolveMacro._

final class CanResolveMacro(val c: Context) {
@bundle
final class CanResolveMacro(val c: blackbox.Context) {

import c.universe._

Expand All @@ -36,14 +39,17 @@ final class CanResolveMacro(val c: Context) {
}
}

final class CanResolveMacroK(val c: Context) {
@bundle
final class CanResolveMacroK(val c: blackbox.Context) {

import c.universe._

def mkImplicitlyBlock[G[_], F[_[_]]](imports: c.Expr[Unit])(
implicit wtf: c.WeakTypeTag[F[G]], wta: c.WeakTypeTag[G[_]]): c.Expr[F[G]] = {
val curried: List[Type] = wtf.tpe match {
case p: PolyType => p.resultType.typeArgs.tail
case p: PolyType =>
val TypeRef(_, _, typeArgs) = p.resultType
typeArgs.tail
case _ => List.empty
}
val resolve = wtf
Expand All @@ -58,12 +64,11 @@ final class CanResolveMacroK(val c: Context) {
q"implicitly[$sym[..${wta.tpe :: curried}]]"
}
}
val expr = c.Expr[F[G]](q"""
c.Expr[F[G]](q"""
{
..$imports
..${resolve.reverse}
}
""")
expr
}
}

0 comments on commit c0d8f24

Please sign in to comment.