Skip to content

Commit

Permalink
Merge pull request #98 from propensive/known-direct-and-indirect-subc…
Browse files Browse the repository at this point in the history
…lasses

Calculate all leaf nodes for knownDirectSubclasses
  • Loading branch information
propensive authored Jun 5, 2018
2 parents dfb9ece + be5fef3 commit a59b1e7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion core/shared/src/main/scala/magnolia.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ object Magnolia {

def error(msg: String) = c.abort(c.enclosingPosition, msg)

def knownSubclasses(sym: ClassSymbol): List[Symbol] = {
val children = sym.knownDirectSubclasses.toList
val (abstractTypes, concreteTypes) = children.partition(_.isAbstract)

abstractTypes.map(_.asClass).flatMap(knownSubclasses(_)) ::: concreteTypes
}

val typeDefs = prefixType.baseClasses.flatMap { cls =>
cls.asType.toType.decls.filter(_.isType).find(_.name.toString == "Typeclass").map { tpe =>
tpe.asType.toType.asSeenFrom(prefixType, cls)
Expand Down Expand Up @@ -326,7 +333,7 @@ object Magnolia {
}})}))
}""")
} else if (isSealedTrait) {
val genericSubtypes = classType.get.knownDirectSubclasses.toList
val genericSubtypes = knownSubclasses(classType.get)
val subtypes = genericSubtypes.map { sub =>
val subType = sub.asType.toType // FIXME: Broken for path dependent types
val typeParams = sub.asType.typeParams
Expand Down

0 comments on commit a59b1e7

Please sign in to comment.