aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Pretty <jon.pretty@propensive.com>2017-06-10 13:24:44 +0200
committerJon Pretty <jon.pretty@propensive.com>2017-06-10 13:24:44 +0200
commitf3a9707a2f3528ff11543c903158ecdf12d40c3a (patch)
tree45f04434db5cc046f15aa9b07b2fdfd70dc68de8
parentd72c7223282f3d64fb1df3e647c1c2a75b8c1bb5 (diff)
downloadmagnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.tar.gz
magnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.tar.bz2
magnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.zip
Fixed (I think) last remaining recursion bug
-rw-r--r--core/src/main/scala/generic.scala18
-rw-r--r--tests/shared/src/main/scala/magnolia/main.scala10
2 files changed, 14 insertions, 14 deletions
diff --git a/core/src/main/scala/generic.scala b/core/src/main/scala/generic.scala
index f8ecc21..a353677 100644
--- a/core/src/main/scala/generic.scala
+++ b/core/src/main/scala/generic.scala
@@ -113,18 +113,20 @@ abstract class GenericMacro(whiteboxContext: whitebox.Context) {
log(c)(s"could not find type $genericType in current context")
GlobalMutableState.searchType = Some(genericType)
val inferredImplicit = try Some({
- val imp = c.inferImplicitValue(searchType, false, false)
- /*q"""{
- def $myName: $searchType = $imp
- $myName
- }"""*/
- imp
+ val myName: TermName = TermName(c.freshName(genericType.typeSymbol.name.encodedName.toString.toLowerCase+"Extractor"))
+ GlobalMutableState.wrap(c)(genericType, myName) {
+ val imp = c.inferImplicitValue(searchType, false, false)
+ q"""{
+ def $myName: $searchType = $imp
+ $myName
+ }"""
+ }.get
}) catch {
case e: Exception => None
}
inferredImplicit.map { imp =>
- imp // c.untypecheck(transformer.transform(imp))
+ imp
}.orElse {
directInferImplicit(genericType, typeConstructor)
}
@@ -250,7 +252,7 @@ abstract class GenericMacro(whiteboxContext: whitebox.Context) {
transformedTree
}.getOrElse {
log(c)("failed to derive a tree")
- c.abort(c.enclosingPosition, "Could not infer extractor. Sorry.")
+ c.abort(c.enclosingPosition, "Could not infer typeclass. Sorry.")
}
} catch {
case e@DirectlyReentrantException() => throw e
diff --git a/tests/shared/src/main/scala/magnolia/main.scala b/tests/shared/src/main/scala/magnolia/main.scala
index d01d37a..67db603 100644
--- a/tests/shared/src/main/scala/magnolia/main.scala
+++ b/tests/shared/src/main/scala/magnolia/main.scala
@@ -1,17 +1,15 @@
package magnolia
-sealed trait Bar
+sealed trait Tree
-case class Foo(one: String) extends Bar
-case class Quux(two: String, three: Double, four: List[Bar]) extends Bar
-case class Bippy(five: String, six: List[Quux]) extends Bar
-class Baz(val x: Bar) extends AnyVal
+case class Branch(left: List[Leaf]) extends Tree
+case class Leaf(node: List[String], right: List[Branch], left2: List[Branch], another: List[Leaf]) extends Tree
object Main {
def main(args: Array[String]): Unit = {
- println(implicitly[Extractor[Bar]].extract(Thing("42")))
+ println(implicitly[Extractor[List[Leaf]]].extract(Thing("42")))
}
}