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

Scala 3 enum issue introduced in v0.4.14 #606

Closed
m-kalai opened this issue Sep 11, 2023 · 0 comments · Fixed by #607
Closed

Scala 3 enum issue introduced in v0.4.14 #606

m-kalai opened this issue Sep 11, 2023 · 0 comments · Fixed by #607

Comments

@m-kalai
Copy link

m-kalai commented Sep 11, 2023

We tried to upgrade to 0.4.14 and noticed our tests failing in places where enums were supposed to be decoded. Happens specifically for enums which are "not simple" i.e. they have parameters.

Example:

  enum Colour(val rgb: Int) {
    case Red extends Colour(0xff0000)
    case Green extends Colour(0x00ff00)
    case Blue extends Colour(0x0000ff)
  }

  case class ColourContainer(colour: Colour)

  object ColourContainer {
    given Schema[ColourContainer] = DeriveSchema.gen[ColourContainer]
  }
  
  val codec = summon[BinaryCodec[ColourContainer]]

  
  val cc = ColourContainer(Colour.Red)

  val encoded = codec.encode(cc)
  println(encoded.asString)

  val decoded = codec.decode(encoded)
  println(decoded)

v0.4.13 output

{"colour":"Red"}
Right(ColourContainer(Red))

v0.4.14 output

{"colour":{"Red":{}}}
Left(zio.schema.codec.DecodeError$ReadError: .colour(expected '"' got '{'))
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

Successfully merging a pull request may close this issue.

1 participant