From 2fa873cd0322d21148cf01d94e485e04b03cdb7c Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Fri, 23 Jun 2017 14:20:40 +0200 Subject: Tidied up and made it compile and run --- core/src/main/scala/magnolia.scala | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'core/src/main/scala') diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala index 66d59d0..e2d1341 100644 --- a/core/src/main/scala/magnolia.scala +++ b/core/src/main/scala/magnolia.scala @@ -221,8 +221,8 @@ class Macros(val c: whitebox.Context) { val contraDerivationType = appliedType(contraDerivationTypeclass, List(typeConstructor)) val contraDerivation2Type = appliedType(contraDerivation2Typeclass, List(typeConstructor)) - def findDerivationImplicit[T <: DerivationImplicit](tpe: c.Type, cons: Tree => T): Try[DerivationImplicit] = - Try(cons(c.untypecheck(c.inferImplicitValue(tpe, false, false)))) + def findDerivationImplicit[T <: DerivationImplicit](derivationType: c.Type, wrap: Tree => T): Try[DerivationImplicit] = + Try(wrap(c.untypecheck(c.inferImplicitValue(derivationType, false, false)))) val derivationImplicit = findDerivationImplicit(coDerivationType, CovariantDerivationImplicit) @@ -258,17 +258,12 @@ class Macros(val c: whitebox.Context) { val searchType = appliedType(typeConstructor, genericType) Some(q"_root_.magnolia.Lazy[$searchType]($methodAsString)") } - } else { - directInferImplicit(genericType, typeConstructor, derivationImplicit) - } + } else directInferImplicit(genericType, typeConstructor, derivationImplicit) - if(currentStack.frames.isEmpty) recursionStack = Map() + if(currentStack.frames.isEmpty) recursionStack = ListMap() result.map { tree => - if(currentStack.frames.isEmpty) { - val res = c.untypecheck(removeLazy.transform(tree)) - res - } else tree + if(currentStack.frames.isEmpty) c.untypecheck(removeLazy.transform(tree)) else tree }.getOrElse { c.abort(c.enclosingPosition, "could not infer typeclass for type $genericType") } @@ -312,8 +307,8 @@ private[magnolia] object CompileTimeState { def termName(c: whitebox.Context): c.TermName = term.asInstanceOf[c.TermName] } - private[magnolia] var recursionStack: Map[api.Position, Stack] = - Map() + private[magnolia] var recursionStack: ListMap[api.Position, Stack] = + ListMap() private[magnolia] var emittedErrors: Set[ImplicitNotFound] = Set() } -- cgit v1.2.3