zio / zio-schema

Compositional, type-safe schema definitions, which enable auto-derivation of codecs and migrations.
https://zio.dev/zio-schema
Apache License 2.0
135 stars 151 forks source link

Schema derivation fails for enumeration with empty sub-tree #667

Open dubinsky opened 4 months ago

dubinsky commented 4 months ago

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]
jdegoes commented 1 month ago

/bounty $75

algora-pbc[bot] commented 1 month ago

💎 $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 bounty • Share on socials

varshith257 commented 3 weeks ago

/attempt #667

algora-pbc[bot] commented 3 weeks ago

@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. 🫡

987Nabil commented 3 weeks ago

@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

varshith257 commented 3 weeks ago

@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