From 8956ec30453923d1dafe42f35fbcb2016ade811f Mon Sep 17 00:00:00 2001 From: Zacharias Kull Date: Sun, 6 Dec 2020 16:49:44 +0100 Subject: [PATCH] fix error 'X is not a concrete case class' caused by uninitialized types The error occurs especially for sealed traits in bigger projects. I was not able to reproduce it in a unit test. I guess the JVM/Scala might initialize type metadata or not, it's not under our control until we force the initialization. --- core/src/main/scala/configs/macros/Construct.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/configs/macros/Construct.scala b/core/src/main/scala/configs/macros/Construct.scala index 8294f3c..88f1044 100644 --- a/core/src/main/scala/configs/macros/Construct.scala +++ b/core/src/main/scala/configs/macros/Construct.scala @@ -70,13 +70,15 @@ trait Construct { if (s.isAbstract) acc else if (s.isCaseClass) member(s) :: acc else abort(a, s"$s is not abstract") - s.typeSignature - collect(s.knownDirectSubclasses.toList.map(_.asClass) ::: ss, accN) + val subclasses = s.knownDirectSubclasses.toList.map(_.asClass) + subclasses.foreach(_.typeSignature) // force initialize type metadata + collect(subclasses ::: ss, accN) case s :: ss if !s.isAbstract && s.isCaseClass => collect(ss, member(s) :: acc) case s :: _ => abort(a, s"$s is not a concrete case class") } + a.typeSignature // force initialize type metadata, otherwise some attributes are empty/false, e.g. isCaseClass, knownDirectSubclasses collect(a :: Nil, Nil) match { case Nil => abort(a, "no known subclasses") case (cc: CaseClass) :: Nil if cc.tpe =:= a.toType => cc