From c0d8f24d0813fd9eaa76121dd09999f809ad91a6 Mon Sep 17 00:00:00 2001 From: yilinwei Date: Tue, 16 May 2017 23:32:01 +0100 Subject: [PATCH] add macro-compat to fix for scala 2.10.6 --- build.sbt | 6 +++++- .../src/main/scala/cats/macros/canResolve.scala | 17 +++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/build.sbt b/build.sbt index 25a270f7c7..3aad7a766b 100644 --- a/build.sbt +++ b/build.sbt @@ -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) @@ -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 diff --git a/macros/src/main/scala/cats/macros/canResolve.scala b/macros/src/main/scala/cats/macros/canResolve.scala index d29344b496..e6a627d0c3 100644 --- a/macros/src/main/scala/cats/macros/canResolve.scala +++ b/macros/src/main/scala/cats/macros/canResolve.scala @@ -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] @@ -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._ @@ -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 @@ -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 } }