Closed plokhotnyuk closed 5 years ago
Well, this looks like a relatively simple initialization order problem to me. Essentially this is the setup:
class Foo {
implicit val charCodec: Codec[Char] = ...
implicit val fooCodec = {
<expr using charCodec>
}
}
This works as long as charCodec
is initialized before fooCodec
but will throw an NPE if you move it below the fooCodec
definition.
This is not really a BORER issue but an artifact of how Scala works.
Do you have an idea on what we might improve here?
Can it be checked in a compile time (with a compilation error throwing) instead of failing differently in the run-time?
As an example, if you remove the lazy
keyword in this line you will get the following compilation error:
Error:(1362, 37) forward reference extends over definition of value intCodec
verifySerDeser(make[List[Int]](CodecMakerConfig()), List(1, 2), "[\"1\",\"2\"]")
Closing as out-of-scope. Initialization order issues are inherent to Scala and cannot really be solved on the level of this library.
To reproduce the stacktrace bellow need to move this line to be bellow this derivation and run this test.