aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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")))
}
}