zio-schema icon indicating copy to clipboard operation
zio-schema copied to clipboard

Schema derivation fails for enumeration with empty sub-tree

Open dubinsky opened this issue 11 months ago • 6 comments

Schema derivation fails when intermediate types with no leaf case objects/classes derived from them are present in the sealed trait (or sealed abstract class) hierarchy.

I can understand failure to derive the schema if the whole hierarchy is empty (no leaf case class/object nodes at all), even though I think it should still work; but failing for the example below seems wrong:

//> using scala 3.4.0
//> using dep dev.zio::zio-schema:1.0.1
//> using dep dev.zio::zio-schema-derivation:1.0.1
sealed trait Thing
object Thing:
  sealed trait Intermediate1 extends Thing
  case object Object1 extends Intermediate1
  sealed trait Intermediate2 extends Thing
// with the following line commented out: "Deriving schema for Thing is not supported"
//  case object Object2 extends Intermediate2
  given schema: zio.schema.Schema[Thing] = zio.schema.DeriveSchema.gen[Thing]

dubinsky avatar Mar 10 '24 23:03 dubinsky

/bounty $75

jdegoes avatar Jun 08 '24 01:06 jdegoes

💎 $75 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #667 with your implementation plan
  2. Submit work: Create a pull request including /claim #667 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-schema!

Add a bountyShare on socials

algora-pbc[bot] avatar Jun 08 '24 01:06 algora-pbc[bot]

/attempt #667

varshith257 avatar Jun 30 '24 18:06 varshith257

@varshith257: We appreciate your enthusiasm but since you already have 3 active bounty attempts, we're going to keep this open for other contributors to attempt. 🫡

algora-pbc[bot] avatar Jun 30 '24 18:06 algora-pbc[bot]

@jdegoes I think this is not an easy fix. The issue seems for me to be, that our derivation depends on the Mirror generated from the Scala 3 compiler. But in the case of a trait as a leave, there is no Mirror generated it seems. I think we don't need to rely on Mirror, but that would mean a big refactoring

987Nabil avatar Jun 30 '24 19:06 987Nabil

@987Nabil But it would be good if we move out relying on Mirror. It allows us lot flexibility. But yes, it gonna something big refactoring. Let's wait for @jdegoes thoughts on this

varshith257 avatar Jul 01 '24 03:07 varshith257