Scala v2.13.11 issues a warning for the following code from the pureconfig orElse documentation (bottom of the page):
val csvIntListReader = ConfigReader[String].map(_.split(",").map(_.toInt).toList)
implicit val intListReader = ConfigReader[List[Int]].orElse(csvIntListReader)
case class IntListConf(list: List[Int])
The warning is:
[warn] Implicit definition should have explicit type (inferred pureconfig.ConfigReader[List[Int]])
[warn] implicit val intListReader = ConfigReader[List[Int]].orElse(csvIntListReader)
[warn] ^
When I add the inferred type, ConfigReader[List[Int]]
, it compiles without the warning but I get a NullPointerException
at run-time.
This raises the following questions for me:
- Why does this work when we let the compiler infer the type but it does not when we explicitly supply the type the compiler says it inferred?
- Is there a type that can be explicitly given to
intListReader
that will compile without a warning and run without error? - If 3 is not possible, is adding
@nowarn
"safe" (eg still work with Scala3)?
Thanks for your insights.
PS: My run-time tests are also from the documentation:
ConfigSource.string("""{ list = [1,2,3] }""").load[IntListConf] ==> Right(IntListConf(List(1, 2, 3)))
and
ConfigSource.string("""{ list = "4,5,6" }""").load[IntListConf] ==> Right(IntListConf(List(4, 5, 6)))