From 86c66ba93b5dc15301ac305fa28e24952e232613 Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Mon, 30 Oct 2017 13:58:33 +0100 Subject: All variants now deriving Though there's a stack overflow when trying to derive a `Decoder`. --- core/src/main/scala/magnolia.scala | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'core/src/main/scala/magnolia.scala') diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala index 9da9f1e..c4c8113 100644 --- a/core/src/main/scala/magnolia.scala +++ b/core/src/main/scala/magnolia.scala @@ -20,6 +20,12 @@ trait Param[Tc[_], T] { def dereference(param: T): S } +trait JoinContext[Tc[_], T] { + def construct[R](param: ((Param[Tc, T]) => Any)): T + def typeName: String + def parameters: List[Param[Tc, T]] +} + object Magnolia { import CompileTimeState._ @@ -156,10 +162,17 @@ object Magnolia { }""" } - val constructor = q"null" //q"""{ => new ${}(..$params) }""" + val constructor = q"""new $genericType(..${callables.zip(implicits).map { case (call, imp) => + q"fn($call).asInstanceOf[${imp._1.returnType}]" + } })""" val impl = q""" - ${c.prefix}.join(${constructor}, $className, _root_.scala.List(..$callables)) + ${c.prefix}.join(new _root_.magnolia.JoinContext[$typeConstructor, $genericType] { + def construct[R](fn: ((Param[${typeConstructor}, $genericType]) => Any)): $genericType = $constructor + def typeName: _root_.java.lang.String = $className + def parameters: _root_.scala.List[Param[$typeConstructor, $genericType]] = + _root_.scala.List(..$callables) + }) """ q""" -- cgit v1.2.3