From a19b4d22b4caffbed551182b20657588b470230b Mon Sep 17 00:00:00 2001 From: Jon Pretty Date: Fri, 10 Nov 2017 14:57:55 +0000 Subject: Attempt to allow the `Typeclass` definition to be defined in supertrait --- core/src/main/scala/magnolia.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala index 293d0f1..f7e9b0e 100644 --- a/core/src/main/scala/magnolia.scala +++ b/core/src/main/scala/magnolia.scala @@ -71,8 +71,16 @@ object Magnolia { val magnoliaObj = q"$magnoliaPkg.Magnolia" val arrayCls = tq"_root_.scala.Array" - val typeConstructor: c.Type = - c.prefix.tree.tpe.member(TypeName("Typeclass")).asType.toType.typeConstructor + val typeDefinitions = + c.prefix.tree.tpe.baseClasses.flatMap(_.asType.toType.decls).filter(_.isType) + + val typeConstructorOpt = + typeDefinitions.find(_.name.toString == "Typeclass").map(_.asType.toType.typeConstructor) + + val typeConstructor = typeConstructorOpt.getOrElse { + c.abort(c.enclosingPosition, "magnolia: the derivation object does not define the Typeclass "+ + "type constructor") + } def findType(key: Type): Option[TermName] = recursionStack(c.enclosingPosition).frames.find(_.genericType == key).map(_.termName(c)) -- cgit v1.2.3