Description
Summary
The codec for a sealed trait using macro does not always work. If the sealed trait and the Macro are not defined is the same module, we have the following error `No known subclasses of the sealed trait`
There is an issue in Scala describing the problem _https://github.com/scala/bug/issues/7755_
How to Reproduce
mongo-scala-driver 4.9.1
scala 2.13.10
Define a sealed trait in a module and use the Macro in a an another module.
// Module 1
|
sealed trait TestIssue
|
case class Issue1(name: String) extends TestIssue |
case class Issue2(name: String, description: String) extends TestIssue |
// Module 2
|
Macros.createCodecProviderIgnoreNone[TestIssue]()
|
To fix this issue, we can change the method `isCaseClass` in `org.mongodb.scala.bson.codecs.macrocodecs.CaseClassCodec`:
def isCaseClass(t: Type): Boolean = {
|
val _ = t.typeSymbol.typeSignature
|
t.typeSymbol.isClass && t.typeSymbol.asClass.isCaseClass && !t.typeSymbol.isModuleClass
|
}
|