@@ -143,12 +143,20 @@ object JsonCodecMaker {
143
143
s " of a sealed definition for ' $tpe' or using a custom implicitly accessible codec for the ADT base. " ))
144
144
}
145
145
146
- def adtLeafClasses (tpe : Type ): Set [Type ] = tpe.typeSymbol.asClass.knownDirectSubclasses.flatMap { s =>
147
- val subTpe = s.asClass.toType
148
- if (isSealedAdtBase(subTpe)) adtLeafClasses(subTpe)
149
- else if (s.asClass.isCaseClass) Set (subTpe)
150
- else fail(" Only case classes & case objects are supported for ADT leaf classes. Please consider using " +
151
- s " of them for ADT with base ' $tpe' or using a custom implicitly accessible codec for the ADT base. " )
146
+ def adtLeafClasses (tpe : Type ): Seq [Type ] = {
147
+ def collectRecursively (tpe : Type ): Set [Type ] =
148
+ tpe.typeSymbol.asClass.knownDirectSubclasses.flatMap { s =>
149
+ val subTpe = s.asClass.toType
150
+ if (isSealedAdtBase(subTpe)) collectRecursively(subTpe)
151
+ else if (s.asClass.isCaseClass) Set (subTpe)
152
+ else fail(" Only case classes & case objects are supported for ADT leaf classes. Please consider using " +
153
+ s " of them for ADT with base ' $tpe' or using a custom implicitly accessible codec for the ADT base. " )
154
+ }
155
+
156
+ val classes = collectRecursively(tpe).toSeq
157
+ if (classes.isEmpty) fail(s " Cannot find leaf classes for ADT base ' $tpe'. Please consider adding them or " +
158
+ " using a custom implicitly accessible codec for the ADT base." )
159
+ classes
152
160
}
153
161
154
162
def companion (tpe : Type ): Tree = Ident (tpe.typeSymbol.companion)
@@ -702,7 +710,7 @@ object JsonCodecMaker {
702
710
JsonReader .toHashCode(cs, cs.length)
703
711
}
704
712
705
- val leafClasses = adtLeafClasses(tpe).toSeq
713
+ val leafClasses = adtLeafClasses(tpe)
706
714
val discrName = codecConfig.discriminatorFieldName
707
715
checkDiscriminatorValueCollisions(discrName, leafClasses.map(discriminatorValue))
708
716
val discriminatorValueError = q " in.discriminatorValueError( $discrName) "
0 commit comments