diff options
author | Jon Pretty <jon.pretty@propensive.com> | 2017-06-10 13:24:44 +0200 |
---|---|---|
committer | Jon Pretty <jon.pretty@propensive.com> | 2017-06-10 13:24:44 +0200 |
commit | f3a9707a2f3528ff11543c903158ecdf12d40c3a (patch) | |
tree | 45f04434db5cc046f15aa9b07b2fdfd70dc68de8 /core/src/main/scala/generic.scala | |
parent | d72c7223282f3d64fb1df3e647c1c2a75b8c1bb5 (diff) | |
download | magnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.tar.gz magnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.tar.bz2 magnolia-f3a9707a2f3528ff11543c903158ecdf12d40c3a.zip |
Fixed (I think) last remaining recursion bug
Diffstat (limited to 'core/src/main/scala/generic.scala')
-rw-r--r-- | core/src/main/scala/generic.scala | 18 |
1 files changed, 10 insertions, 8 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 |