Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comma-separated parsing does not work with sealed hierarchies #1194

Open
paulpdaniels opened this issue Jun 13, 2023 · 0 comments
Open

Comma-separated parsing does not work with sealed hierarchies #1194

paulpdaniels opened this issue Jun 13, 2023 · 0 comments

Comments

@paulpdaniels
Copy link

Consider the following:

import zio._
import zio.config._
import zio.config.magnolia._
import zio.config.typesafe._

sealed trait EnumConfig

object EnumConfig {
  case object One extends EnumConfig
  case object Two extends EnumConfig
  case object Three extends EnumConfig
}

case class OuterConfig(list: List[EnumConfig])

val outerConfig = DeriveConfig.deriveConfig[OuterConfig].nested("outer")

val hocon = """
outer {
  list = "One,Two,Three"
}
"""

val provider = ConfigProvider.fromHoconString(hocon, true)
Unsafe.unsafe { implicit u =>
  Runtime.default.unsafe.run(
  ZIO
    .config(outerConfig)
    .flatMap(c => ZIO.debug(c))
    .provide(Runtime.setConfigProvider(provider)))
}

Scastie: https://scastie.scala-lang.org/YzsMuk4iTzSNxqIg0fVv2w

Running this example will result in an error about the list field needing to be a constant. However, if you change the list: List[EnumConfig] to list: List[String] the resulting config is parsed correctly as a list of strings.

At the moment, I have only attempted this with typesafe so I'm not sure how it affects other providers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant