You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I'm pretty new to Scala and ZIO so I hope my report is qualified. Here is a minimal example to reproduce a suspected bug, that I coincidentally discovered in a more complex scenario:
The test can be easily fixed by defining the implicits in the order aEncoder, aOptionEncoder, bEncoder. However, the problem seems to be specifically related to HKT because using aOptionEncoder, bEncoder, aEncoder won't cause a problem although A is nested in B.
I would expect that, if the order of definitions matters, there will be a compile or build error. However, the error occurs only at runtime.
Scala 2.13.11
zio 2.0.16
zio-json 0.6.1
The text was updated successfully, but these errors were encountered:
unfortunately, this is actually not limited to higher kinded types. here's an even smaller example:
import zio.ZIO
import zio.json.{DeriveJsonEncoder, EncoderOps, JsonEncoder}
import zio.test._
object EncodeJsonSpec extends ZIOSpecDefault {
case class A()
case class B(a: A)
implicit val bEncoder: JsonEncoder[B] = DeriveJsonEncoder.gen
implicit val aEncoder: JsonEncoder[A] = DeriveJsonEncoder.gen
def spec =
suite("JsonSpec")(
test("Encode JSON") {
for {
json <- ZIO.attempt(B(a = A()).toJson)
} yield assertTrue(json != null)
}
)
}
causes a null pointer exception inside the macro:
Exception in thread "zio-fiber-77" java.lang.NullPointerException: null
at zio.json.DeriveJsonEncoder$$anon$6.unsafeEncode(macros.scala:560)
at zio.json.JsonEncoder.encodeJson(JsonEncoder.scala:75)
at zio.json.JsonEncoder.encodeJson$(JsonEncoder.scala:73)
at zio.json.DeriveJsonEncoder$$anon$6.encodeJson(macros.scala:531)
at zio.json.package$EncoderOps$.toJson$extension(package.scala:22)
Hello. I'm pretty new to Scala and ZIO so I hope my report is qualified. Here is a minimal example to reproduce a suspected bug, that I coincidentally discovered in a more complex scenario:
The test can be easily fixed by defining the implicits in the order
aEncoder, aOptionEncoder, bEncoder
. However, the problem seems to be specifically related to HKT because usingaOptionEncoder, bEncoder, aEncoder
won't cause a problem although A is nested in B.I would expect that, if the order of definitions matters, there will be a compile or build error. However, the error occurs only at runtime.
Scala 2.13.11
zio 2.0.16
zio-json 0.6.1
The text was updated successfully, but these errors were encountered: