aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/scala/generic.scala14
-rw-r--r--tests/shared/src/main/scala/magnolia/main.scala3
2 files changed, 6 insertions, 11 deletions
diff --git a/core/src/main/scala/generic.scala b/core/src/main/scala/generic.scala
index 5f60ff2..8ba4fd4 100644
--- a/core/src/main/scala/generic.scala
+++ b/core/src/main/scala/generic.scala
@@ -103,12 +103,10 @@ abstract class GenericMacro(whiteboxContext: whitebox.Context) {
typeConstructor: c.universe.Type,
myName: c.universe.TermName): c.Tree = {
- //log(c)(s"getImplicit1($genericType)")
- GlobalMutableState.find(c)(genericType).map { nm =>
- val str = nm.encodedName.toString
+ GlobalMutableState.find(c)(genericType).map { methodName =>
+ val methodAsString = methodName.encodedName.toString
val searchType = appliedType(typeConstructor, genericType)
- q"$str.asInstanceOf[${searchType}]"
- q"_root_.magnolia.Lazy[$searchType]($str)"
+ q"_root_.magnolia.Lazy[$searchType]($methodAsString)"
}.orElse {
val searchType = appliedType(typeConstructor, genericType)
if(GlobalMutableState.find(c)(genericType).isEmpty) {
@@ -127,9 +125,7 @@ abstract class GenericMacro(whiteboxContext: whitebox.Context) {
case e: Exception => None
}
- inferredImplicit.map { imp =>
- imp
- }.orElse {
+ inferredImplicit.orElse {
directInferImplicit(genericType, typeConstructor)
}
} else {
@@ -146,8 +142,6 @@ abstract class GenericMacro(whiteboxContext: whitebox.Context) {
log(c)(s"directInferImplicit($genericType) given definitions for ${GlobalMutableState.enclosingTypes(c).mkString("{", ", ", "}")}")
- //if(genericType.typeSymbol.isAbstract) log(c)(s"cannot derive typeclass for abstract type $genericType")
-
val myName: TermName = TermName(c.freshName(genericType.typeSymbol.name.encodedName.toString.toLowerCase+"Extractor"))
val typeSymbol = genericType.typeSymbol
val classType = if(typeSymbol.isClass) Some(typeSymbol.asClass) else None
diff --git a/tests/shared/src/main/scala/magnolia/main.scala b/tests/shared/src/main/scala/magnolia/main.scala
index 67db603..213e87e 100644
--- a/tests/shared/src/main/scala/magnolia/main.scala
+++ b/tests/shared/src/main/scala/magnolia/main.scala
@@ -4,12 +4,13 @@ sealed trait Tree
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
+case class Twig(alpha: List[Twig], beta: List[Leaf], gamma: String, delta: List[Tree]) extends Tree
object Main {
def main(args: Array[String]): Unit = {
- println(implicitly[Extractor[List[Leaf]]].extract(Thing("42")))
+ println(implicitly[Extractor[List[Twig]]].extract(Thing("42")))
}
}