aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/scala/magnolia.scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/scala/magnolia.scala')
-rw-r--r--core/src/main/scala/magnolia.scala11
1 files changed, 8 insertions, 3 deletions
diff --git a/core/src/main/scala/magnolia.scala b/core/src/main/scala/magnolia.scala
index f7e9b0e..6be8ed0 100644
--- a/core/src/main/scala/magnolia.scala
+++ b/core/src/main/scala/magnolia.scala
@@ -71,11 +71,16 @@ object Magnolia {
val magnoliaObj = q"$magnoliaPkg.Magnolia"
val arrayCls = tq"_root_.scala.Array"
- val typeDefinitions =
- c.prefix.tree.tpe.baseClasses.flatMap(_.asType.toType.decls).filter(_.isType)
+ val prefixType = c.prefix.tree.tpe
+
+ val typeDefs = prefixType.baseClasses.flatMap { cls =>
+ cls.asType.toType.decls.filter(_.isType).find(_.name.toString == "Typeclass").map { tpe =>
+ tpe.asType.toType.asSeenFrom(prefixType, cls)
+ }
+ }
val typeConstructorOpt =
- typeDefinitions.find(_.name.toString == "Typeclass").map(_.asType.toType.typeConstructor)
+ typeDefs.headOption.map(_.typeConstructor)
val typeConstructor = typeConstructorOpt.getOrElse {
c.abort(c.enclosingPosition, "magnolia: the derivation object does not define the Typeclass "+