Skip to content

Commit

Permalink
Improve deriveAll error message for simple enums, ref #695
Browse files Browse the repository at this point in the history
  • Loading branch information
sirthias committed Jun 30, 2024
1 parent 17734fe commit 2432277
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions derivation/src/main/scala/io/bullet/borer/derivation/Deriver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,17 @@ abstract private[derivation] class Deriver[F[_]: Type, T: Type, Q <: Quotes](usi
* breaking dependency cycles.
*/
final def subtypesNeedingTypeclassDerivation[F[_] : Type](rootNode: AdtTypeNode): (List[TypeRepr], List[TypeRepr]) = {
val subNodes = flattenedSubs[F](rootNode, deepRecurse = false, includeEnumSingletonCases = false)
val subNodesInclSingletonCases = flattenedSubs[F](rootNode, deepRecurse = false, includeEnumSingletonCases = true)
val (singletonCases, subNodes) = subNodesInclSingletonCases.partition(_._1.isEnumSingletonCase)
if (subNodes.isEmpty)
fail(
s"""Could not find any sub-types of `$theTname`, likely because `$theTname` is not a fully closed ADT.
|Do you maybe have a `sealed trait` somewhere, which has no subclasses?""".stripMargin)
fail {
if (singletonCases.isEmpty)
s"""Could not find any sub-types of `$theTname`, likely because `$theTname` is not a fully closed ADT.
|Do you maybe have a `sealed trait` somewhere, which has no subclasses?""".stripMargin
else
s"""This enum does not define any sub-classes.
|You can therefore replace the `deriveAll` with a simple `derive`""".stripMargin
}

val subTypesWithoutTC = subNodes.toList.collect { case (node, false) => node.tpe }
if (subTypesWithoutTC.isEmpty)
Expand Down

0 comments on commit 2432277

Please sign in to comment.