diff options
Diffstat (limited to 'core/src/main/scala')
-rw-r--r-- | core/src/main/scala/magnolia.scala | 12 |
1 files changed, 10 insertions, 2 deletions
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)) |